public static bool IsSome <T>(this Option <T> @this) => @this.Match( () => false, (_) => true);
internal static T ValueUnsafe <T>(this Option <T> @this) => @this.Match( () => { throw new InvalidOperationException(); }, (t) => t);
public static bool HasValue <TValue>(this Option <TValue> option) => option.Match(_ => true, () => false);
// utilities public static Unit Match <T>(this Option <T> @this, Action None, Action <T> Some) => @this.Match(None.ToFunc(), Some.ToFunc());
public static Option <T> OrElse <T>(this Option <T> left, Func <Option <T> > right) => left.Match( () => right(), (_) => left);
/// <summary> /// Convert a LanguageExt Option into an F# Option /// </summary> public static FSharpOption <T> ToFsOption <T>(Option <T> option) => option.Match(() => FSharpOption <T> .None, v => FSharpOption <T> .Some(v));
public static Task <TResult> MatchAsync <TValue, TResult>(this Option <TValue> option, Func <TValue, Task <TResult> > some, Func <Task <TResult> > none) where TValue : notnull => option.Match(some, none);
public static Task <T> GetOrElse <T>(this Option <T> opt, Func <Task <T> > fallback) => opt.Match( () => fallback(), (t) => Task.FromResult(t));
public static Option <TValue> OfType <TValue>(this Option <object> option) => option.Match(value => Option.Create(value is TValue, () => (TValue)value), Option.None <TValue>);
public static TValue?ToNullable <TValue>(this Option <TValue> option) where TValue : struct => option.Match(value => (TValue?)value, () => null);
public static Option <TValue> DefaultIfNone <TValue>(this Option <TValue> option, TValue defaultValue = default) => option.Match(Option.Some, () => Option.Some(defaultValue));
public static TValue ValueOrDefault <TValue>(this Option <TValue> option, TValue defaultValue = default) => option.Match(value => value, () => defaultValue);
public static Option <TResult> Bind <TValue, TResult>(this Option <TValue> option, Func <TValue, Option <TResult> > bind) => option.Match(bind, Option.None <TResult>);
public static T GetOrElse <T>(this Option <T> opt, T defaultValue) => opt.Match( () => defaultValue, (t) => t);
public static Task <Option <TResult> > BindAsync <TValue, TResult>(this Option <TValue> option, Func <TValue, Task <Option <TResult> > > bind) => option.Match(bind, () => Task.FromResult(Option.None <TResult>()));
public static T GetOrElse <T>(this Option <T> opt, Func <T> fallback) => opt.Match( () => fallback(), (t) => t);
public static bool HasValue <TValue>(this Option <TValue> option) => option.Match(DelegateCache <TValue> .True, DelegateCache.False);
public static Option <T> OrElse <T>(this Option <T> left, Option <T> right) => left.Match( () => right, (_) => left);
public static Option <R> Bind <T, R> (this Option <T> optT, Func <T, Option <R> > f) => optT.Match( () => None, (t) => f(t));
public static Option <T> Where <T> (this Option <T> optT, Func <T, bool> predicate) => optT.Match( () => None, (t) => predicate(t) ? optT : None);
public static Option <R> Map <T, R> (this Option <T> optT, Func <T, R> f) => optT.Match( () => None, (t) => Some(f(t)));
public static TSome AssertSome <TSome>(this Option <TSome> option) => option.Match(s => s, () => throw new Exception("Option should be some."));
public static bool TryGetValue <TValue>(this Option <TValue> option, out TValue some) { some = option.Match(DelegateCache <TValue> .Passthrough, DelegateCache <TValue> .Default); return(option.Match(DelegateCache <TValue> .True, DelegateCache.False)); }