/// <summary> /// Create a Some of T from a Nullable<T> (Option<T>) /// </summary> /// <typeparam name="T">T</typeparam> /// <param name="value">Non-null value to be made optional</param> /// <returns>Option<T> in a Some state or throws ValueIsNullException /// if value == null</returns> public static Option <T> Some <T>(Nullable <T> value) where T : struct => value.HasValue ? Option <T> .Some(value.Value) : raise <Option <T> >(new ValueIsNullException());
public Option <B> Map <B>(Func <A, B> f) => isSome ? Option <B> .Some(f(Value)) : default;
/// <summary> /// Create a Some of T (Option<T>) /// </summary> /// <typeparam name="T">T</typeparam> /// <param name="value">Non-null value to be made optional</param> /// <returns>Option<T> in a Some state or throws ValueIsNullException /// if value == null.</returns> public static Option <T> Some <T>(T value) => value == null ? raise <Option <T> >(new ValueIsNullException()) : Option <T> .Some(value);
public static Option <Identity <B> > Traverse <A, B>(this Identity <Option <A> > ma, Func <A, B> f) => ma.Value.IsSome ? Option <Identity <B> > .Some(new Identity <B>(f(ma.Value.Value))) : Option <Identity <B> > .None;