protected override Maybe <Type> DefaultTypeFor(Type type) { return (new Maybe <Type>( _container.Apply(c => c.Registrations.FirstOrDefault(r => r.RegisteredType == type)) .Do(r => r.MappedToType))); }
public void Apply_EmptyMaybeReturnsEmptyMaybe() { Maybe <string> str = new Maybe <string>(null); Maybe <object> obj = str.Apply(x => (Object)x); Assert.IsNotNull(obj); Assert.IsFalse(obj.HasValue); }
public void Apply_NullFunctionReturnsEmptyMaybe() { Maybe <string> str = new Maybe <string>("abc"); Maybe <object> obj = str.Apply <object>(null); Assert.IsNotNull(obj); Assert.IsFalse(obj.HasValue); }
public void Apply_EmptyMaybeReturnsEmptyMaybe() { Maybe<string> str = new Maybe<string>(null); Maybe<object> obj = str.Apply(x=>(Object)x); Assert.IsNotNull(obj); Assert.IsFalse(obj.HasValue); }
public void Apply_NullFunctionReturnsEmptyMaybe() { Maybe<string> str = new Maybe<string>("abc"); Maybe<object> obj = str.Apply<object>(null); Assert.IsNotNull(obj); Assert.IsFalse(obj.HasValue); }
public void Apply_NonEmptyMaybeReturnsNonEmptyMaybe() { Maybe <string> str = new Maybe <string>("abc"); Maybe <string> obj = str.Apply(x => x + "123"); Assert.IsNotNull(obj); Assert.IsTrue(obj.HasValue); Assert.AreEqual("abc123", obj.Value); }
public void Apply_NonEmptyMaybeReturnsNonEmptyMaybe() { Maybe<string> str = new Maybe<string>("abc"); Maybe<string> obj = str.Apply(x => x + "123"); Assert.IsNotNull(obj); Assert.IsTrue(obj.HasValue); Assert.AreEqual("abc123", obj.Value); }
private Maybe <TOutput> ProcessResult(Maybe <TInput> item) { if (item.IsEmpty) { // that was the last one ! m_receivedLast = true; LogConsumer("Received last item"); return(Maybe.Nothing <TOutput>()); } LogConsumer("Applying transform on item"); return(Maybe.Apply <TInput, TOutput>(item, m_transform)); }
public bool Third_law(int y) { // u <*> pure y = pure ($ y) <*> u // u <*> (pure y) = (pure ($ y)) <*> u // apply u (pure y) = apply (pure ($ y)) u // apply u (pure y) = apply (pure (\x -> x $ y)) u // apply u (pure y) = apply (pure (\x -> ($) x y)) u // apply u (pure y) = apply (pure (\x -> x y)) u Maybe <Func <int, int> > u = Maybe <Func <int, int> > .Just(i => i + 1); var left = u.Apply(Maybe.Pure(y)); // \x -> x y Func <Func <int, int>, int> f = h => h(y); var right = Maybe.Pure(f).Apply(u); return(left.Equals(right)); }
private string ExecuteInternal(Maybe<string> pipeIn) { StartProcess(); pipeIn.Apply(WriteToStandardIn); var output = GetOutputAndWait(); CheckExitCode(); return output; }
public bool Invoking_applied_nothing_function_with_just_a_value_returns_nothing(int i) { Func <Maybe <int>, Maybe <int> > appliedNothingFunc = NothingFunc.Apply(); return(appliedNothingFunc(Maybe <int> .Just(i)).Equals(Maybe <int> .Nothing)); }
public bool Invoking_applied_elevated_function_with_just_a_value_returns_just_function_result(int i) { Func <Maybe <int>, Maybe <int> > appliedElevatedFunc = ElevatedFunc.Apply(); return(appliedElevatedFunc(Maybe <int> .Just(i)).Equals(Maybe <int> .Just(IntDivBy2(i)))); }
public void Apply() { Func <int, string> func = value => value.ToString(); Assert.Equal("5", Some5.Apply(func.ToSome()).Value); }
public static Maybe <R> Apply <A, R>(this Maybe <Func <A, R> > fn, Maybe <A> @this) => @this.Apply(fn);