fromNullableWith<T> function

Option<T> Function(T? value) fromNullableWith<T>()

A wrapper around fromNullable, that allows the type to be enforced. Useful for function composition.

final maybeString = fromNullableWith<String>();

expect(maybeString('hello'), some('hello'));
expect(maybeString(null), none());
maybeString(123); // <- compiler error

Implementation

Option<T> Function(T? value) fromNullableWith<T>() => fromNullable;