Beispiel #1
0
        /// <summary>
        /// Lifts an inner Task out of the OneOf.
        /// </summary>
        /// <typeparam name="TA"></typeparam>
        /// <typeparam name="TB"></typeparam>
        /// <param name="oneOf"></param>
        /// <returns></returns>
        public static async Task <OneOf <TA, TB> > LiftTask <TA, TB>(this OneOf <TA, Task <TB> > oneOf)
        {
            var isA = oneOf.Extract(x => true, x => false);

            if (isA)
            {
                var a = oneOf.Extract(x => x, x => throw new InvalidOperationException());
                return(new OneOf <TA, TB>(a));
            }

            var b = await oneOf.Extract(x => throw new InvalidOperationException(), x => x);

            return(new OneOf <TA, TB>(b));
        }
Beispiel #2
0
 private static JToken Unwrap <TA, TB>(OneOf <TA, TB> oneOf)
 {
     // TODO: Handle primitives
     return(oneOf.Extract(
                a => JToken.FromObject(a),
                b => JToken.FromObject(b)
                ));
 }
Beispiel #3
0
 /// <summary>
 /// Extracts a value after awaiting the previous result.
 /// </summary>
 public static Task <TResult> Extract <TA, TB, TResult>(
     this OneOf <Task <TA>, Task <TB> > oneOf,
     Func <TA, TResult> fA,
     Func <TB, TResult> fB
     )
 {
     return(oneOf.Extract(
                async x => fA(await x),
                async x => fB(await x)
                ));
 }