public void RequestingValueAfterSourceHasDataPerformsTransformation() { Future <string> source = new Future <string>(); FutureProxy <int> subject = FutureProxy <int> .FromFuture(source, x => x.Length); source.Value = "hello"; Assert.AreEqual(5, subject.Value); }
public void RequestingValueBeforeSourceHasDataPropagatesException() { Future <string> source = new Future <string>(); FutureProxy <int> subject = FutureProxy <int> .FromFuture(source, x => x.Length); try { Console.WriteLine(subject.Value); Assert.Fail("Expected exception"); } catch (InvalidOperationException) { // Expected } }
/// <summary> /// Returns a future that indicates whether all values /// yielded by the data-producer satisfy a given condition. /// The future will return true for an empty sequence or /// where all values satisfy the condition, else false /// (if any value value fails to satisfy the condition). /// </summary> /// <param name="source">The data-producer to be monitored.</param> /// <param name="predicate">The condition that must be satisfied by all terms.</param> public static IFuture <bool> All <TSource>(this IDataProducer <TSource> source, Func <TSource, bool> predicate) { predicate.ThrowIfNull("predicate"); return(FutureProxy <bool> .FromFuture(source.Any(value => !predicate(value)), value => !value)); }