Complete overview of data structures and interfaces
Explore which functional programming interfaces are supported by each data structure in functype
This matrix shows which interfaces are supported by each data structure in the functype library.
All types follow the Companion pattern (inspired by Scala), combining constructor functions with static utility methods. Each type provides:
Static type guards for narrowing types:
| Data Structure | Type Guard Methods |
|---|---|
| Option | isSome(option), isNone(option) |
| Either<L,R> | isLeft(either), isRight(either) |
| Try | isSuccess(tryValue), isFailure(tryValue) |
All Serializable types provide static deserialization methods:
fromJSON(json: string): T - Deserialize from JSONfromYAML(yaml: string): T - Deserialize from YAMLfromBinary(binary: string): T - Deserialize from base64-encoded binaryNote: See docs/companion-pattern.md for complete guide on the Companion pattern.
map<B>(f: (value: A) => B): Functor<B>ap<B>(ff: Applicative<(value: A) => B>): Applicative<B>flatMap<B>(f: (value: A) => Monad<B>): Monad<B>flatMapAsync<B>(f: (value: A) => PromiseLike<AsyncMonad<B>>): PromiseLike<AsyncMonad<B>>fold<B>(onEmpty: () => B, onValue: (value: A) => B): BfoldLeft<B>(z: B): (op: (b: B, a: A) => B) => BfoldRight<B>(z: B): (op: (a: A, b: B) => B) => Bmatch<R>(patterns: Record<Tags, (value: A) => R>): Rserialize(): SerializationMethods<T>
toJSON(): stringtoYAML(): stringtoBinary(): Uint8Arraysize: numberisEmpty: booleancontains(value: A): booleanreduce<B>(f: (acc: B, value: A) => B, initial: B): BreduceRight<B>(f: (value: A, acc: B) => B, initial: B): BorThrow(error?: Error): TorElse(defaultValue: T): Tor(alternative: Extractable<T>): Extractable<T>orNull(): T | nullorUndefined(): T | undefinedpipe<U>(f: (value: T) => U): UtoList(): List<A>toSet(): Set<A>toString(): stringcount(p: (value: A) => boolean): numberfind(p: (value: A) => boolean): A | undefinedexists(p: (value: A) => boolean): booleanforEach(f: (value: A) => void): voiddrop(n: number): SelfdropRight(n: number): SelfdropWhile(p: (value: A) => boolean): Selfflatten(): Selfhead: AheadOption: Option<A>toArray(): A[]Enables Scala-like for-comprehensions using JavaScript generators:
Do(function* () { ... }): Synchronous monadic comprehensionsDoAsync(async function* () { ... }): Async monadic comprehensions$(monad): Helper for type inference with yield*Provides type conversion between monadic types:
toOption(): Option<T>toEither<E>(leftValue: E): Either<E, T>toList(): List<T>toTry(): Try<T>Provides conversion to Promise for async interop:
toPromise(): Promise<T>Functype<A, Tag>: Implemented by single-value containers (Option, Try, Lazy). Provides full functional programming support.
FunctypeCollection<A, Tag>: Implemented by collection containers (List, Set). Extends FunctypeBase with collection-specific operations.
Special Cases:
Do-notation: Provides generator-based monadic comprehensions similar to Scala’s for-comprehensions. Supports Option, Either, Try, and List with automatic short-circuiting and cartesian products.
Reshapeable: Enables conversion between different monad types, allowing flexible composition in Do-notation when mixing types.
Promisable: Provides conversion to Promise for async interoperability. Supported by Option, Either, Try, and TaskOutcome.
Utility Types (not in matrix):