public static Future <B> Select <A, B>(this Future <A> fa, Fn <A, B> f) => fa.map(f);
public static Future <Option <To> > mapO <From, To>( this Future <Option <From> > future, Fn <From, To> mapper ) { return(future.map(opt => opt.map(mapper))); }
public static Future <A> flatten <A>(this Future <Future <A> > future) => future.flatMap(_ => _);
public static Future <Option <A> > ofSuccess <A>(this Future <Try <A> > future) => future.map(e => e.value);
public static Future <Option <Exception> > ofFailure <A>(this Future <Try <A> > future) => future.map(e => e.exception);
public void WhenSuccessful() { Future <int> .successful(1).map(mapper).shouldBeSuccessful(2); }
public static Future <Option <A> > extractOpt <A>(this Option <Future <A> > futureOpt) => futureOpt.fold(() => Future.successful(F.none <A>()), f => f.map(F.some));
public static void shouldBeSuccessful <A>(this Future <A> f, A a) { f.type.shouldEqual(FutureType.Successful); f.shouldBeCompleted(a); }
public static void shouldBeUnfulfilled <A>(this Future <A> f, string message = null) { f.type.shouldEqual(FutureType.Unfulfilled, message); f.value.shouldBeNone($"{message ?? ""}: it shouldn't have a value"); }
public static IEnumerable <Future <A> > addUnfulfilled <A>(this IEnumerable <Future <A> > futures) { return(futures.Concat(Future.unfulfilled <A>().Yield())); }
public void UnfulfilledToASync() { unfulfilledShouldNotCallMapper(i => Future.a <int>(p => {})); }
public static Functional.Lazy <Option <A> > toLazy <A>(this Future <A> f) => F.lazy(() => f.value);
public static Future <C> SelectMany <A, B, C>(this Future <A> fa, Fn <A, Future <B> > f, Fn <A, B, C> g) => fa.flatMap(f, g);
public static Future <B> SelectMany <A, B>(this Future <A> fa, Fn <A, Future <B> > f) => fa.flatMap(f);
void CompleteToComplete() { Future.successful(3).collect(i => F.some(i * 2)).shouldBeCompleted(6); }
public void WhenBothSidesSuccessful() { Future.successful(1).zip(Future.successful(2)).shouldBeSuccessful(F.t(1, 2)); }
void NotCompleteToNotComplete() { Future.unfulfilled <int>().collect(i => F.none <int>()).shouldNotBeCompleted(); Future.unfulfilled <int>().collect(F.some).shouldNotBeCompleted(); }
public static void shouldBeCompleted <A>(this Future <A> f, A a) { f.value.shouldBeSome(a, "it should have a value"); }
public static Future <A> extract <A>(this Future <Option <A> > optFuture) => optFuture.flatMap(opt => opt.fold(Future <A> .unfulfilled, Future.successful));
public static void shouldNotBeCompleted <A>(this Future <A> f) { f.value.shouldBeNone("it should not have a value"); }
public static Future <Option <B> > ofSuccess <A, B>(this Future <Either <A, B> > future) => future.map(e => e.rightValue);
public void CompleteToNotComplete() { Future.successful(3).filter(i => false).shouldNotBeCompleted(); }
public static Future <Option <A> > ofFailure <A, B>(this Future <Either <A, B> > future) => future.map(e => e.leftValue);
void CompleteToComplete() { Future.successful(3).filter(i => true).shouldBeCompleted(3); }
public static LazyVal <Option <A> > toLazy <A>(this Future <A> f) => F.lazy(() => f.value);
void NotCompleteToNotComplete() { Future.unfulfilled <int>().filter(i => false).shouldNotBeCompleted(); Future.unfulfilled <int>().filter(i => true).shouldNotBeCompleted(); }
public static Future <Either <Err, To> > mapE <From, To, Err>( this Future <Either <Err, From> > future, Fn <From, To> mapper ) { return(future.map(e => e.mapRight(mapper))); }
public void CompleteToNotComplete() { Future.successful(3).collect(i => F.none <int>()).shouldNotBeCompleted(); }
/** Complete the future with the right side, never complete if left side occurs. **/ public static Future <B> dropError <A, B>(this Future <Either <A, B> > future) => Future.a <B>(p => future.onSuccess(p.complete));
public static ASyncNAtATimeQueue <Params, Return> a <Params, Return>( Act <Params, Promise <Return> > execute, ushort maxTasks = 1 ) => new ASyncNAtATimeQueue <Params, Return>( maxTasks, p => Future <Return> .async(promise => execute(p, promise)) );