option library

Classes

None<A>
Represents a missing value.
Option<T>
Represents a value that could be missing - an [option]al value.
Some<A>
Represents a present value. The value property contains the wrapped value.

Constants

kNone → const Option<Never>
A constant version on None, as Option<Never>.

Functions

alt<T>(Lazy<Option<T>> f) Option<T> Function(Option<T> option)
If the Option is a None, then the result of the given function will determine the [alt]ernate / replacement Option.
chainNullableK<A, B>(B? f(A value)) Option<B> Function(Option<A> option)
Returns an function that transforms an Option. If the given transformer returns null, then None is returned.
chainTryCatchK<A, B>(B f(A value)) Option<B> Function(Option<A> a)
A variant of tryCatchK, that allows for passing in an Option. If the Option is Some, then the value is unwrapped and passed into the function.
Do<A>(DoFunction<A> f) Option<A>
filter<T>(bool predicate(T value)) Option<T> Function(Option<T> option)
Using the given predicate, conditionally convert the Option to a None.
flatMap<A, B>(Option<B> f(A value)) Option<B> Function(Option<A> option)
Transform the Option into another Option, using the given function.
flatMapTuple2<A, A2>(Option<A2> f(A a)) Option Function(Option<A> o)
A variant of flatMap that appends the result to a tuple.
flatMapTuple3<A, A2, A3>(Option<A3> f(dynamic a)) Option<Tuple3<A, A2, A3>> Function(Option o)
A variant of flatMap that appends the result to a tuple.
flatten<A>(Option<Option<A>> option) Option<A>
Flatten's nested Option to a single level.
fold<A, B>(B ifNone(), B ifSome(A value)) → B Function(Option<A> option)
Transforms an Option into a value, using the ifNone and ifSome functions.
fromEither<L, R>(Either<L, R> either) Option<R>
Transforms an Either into an Option. Right becomes Some, and Left becomes None.
fromNullable<T>(T? value) Option<T>
Returns an Option that returns Some or None, depending on whether it is null or not.
fromNullableK<A, B>(B? f(A value)) Option<B> Function(A value)
Returns an function that transforms a value and can return a nullable result. If the result is null, then None is returned. Otherwise it is wrapped in Some.
fromNullableWith<T>() Option<T> Function(T? value)
A wrapper around fromNullable, that allows the type to be enforced. Useful for function composition.
fromPredicate<T>(T value, bool predicate(T value)) Option<T>
Returns a Some or None if the predicate returns true or false respectively.
fromPredicateK<T>(bool predicate(T value)) Option<T> Function(T value)
Wrapper around fromPredicate that can be curried with the value.
getOrElse<T>(Lazy<T> orElse) → T Function(Option<T> option)
Unwrap the Option's value if it is Some, otherwise it calls the orElse function to determine the fallback value.
isNone<T>(Option<T> option) bool
Returns true if the Option is a None.
isSome<T>(Option<T> option) bool
Returns true if the Option is a Some.
map<T, R>(R f(T value)) Option<R> Function(Option<T> option)
Transform the wrapped value if the Option is a Some, using the provided function.
map2<A, B, R>(R f(A a, B b)) Option<R> Function(Option<A> optionA, Option<B> optionB)
Creates a function that accepts two Option's, and if both of them are Some, then the transformer function is called with the unwrapped values.
map2K<A, B, R>(Option<B> optionB, R f(A a, B b)) Option<R> Function(Option<A> optionA)
A wrapper around map2, useful for chaining. The second Option is passed as the first argument.
map3<A, B, C, R>(R f(A a, B b, C c)) Option<R> Function(Option<A> optionA, Option<B> optionB, Option<C> optionC)
Creates a function that accepts three Option's, and if they are all Some, then the transformer function is called with the unwrapped values.
map3K<A, B, C, R>(Option<B> optionB, Option<C> optionC, R f(A a, B b, C c)) Option<R> Function(Option<A> optionA)
A wrapper around map3, useful for chaining. The remaining Option's are passed as arguments.
mapTuple2<A, B, R>(R f(A a, B b)) Option<R> Function(dynamic tuple)
A variant of map2, that accepts the two Option's as a Tuple2.
mapTuple3<A, B, C, R>(R f(A a, B b, C c)) Option<R> Function(Tuple3<Option<A>, Option<B>, Option<C>> tuple)
A variant of map3, that accepts the Option's as a Tuple3.
none<T>() Option<T>
Returns an Option that resolves to a None. Represents a value that does not exists.
some<T>(T value) Option<T>
Returns an Option that resolves to a Some, which wraps the given value. Represents a value that does exist.
tap<A>(void f(A value)) Option<A> Function(Option<A> option)
Execute a side effect on the wrapped value, if the Option is a Some.
toNullable<T>(Option<T> option) → T?
Transforms the Option into a nullable value. Some unwraps to the value, while None becomes null.
traverse<A, B>(Option<B> f(A a)) Option<IList<B>> Function(Iterable<A>)
tryCatch<T>(T f()) Option<T>
Returns the value as a Some if the function succeeds. If it raises an exception, then it will return None.
tryCatchK<A, B>(B f(A value)) Option<B> Function(A a)
A variant of tryCatch, that allows for passing in external values.

Typedefs

DoFunction<A> = A Function(_DoAdapter $)