public static void LinqWriterTest() { var cxt = new WriterCxt <IList <string>, Monoid.ListAppendImmutableMonoid <string> >(); bool m = true; var computation = from _1 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 1"))) from _2 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 2"))) from _3 in MaybeT.HoistWriter(cxt, Maybe.JustIf(m, () => new Unit())) from _4 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 3"))) select 5; var value = computation.Run; Assert.True(value.Result.HasValue); Assert.Equal(5, value.Result.Value()); Assert.Equal(new[] { "function call 1", "function call 2", "function call 3" }, (IEnumerable <string>)value.State); m = false; computation = from _1 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 1"))) from _2 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 2"))) from _3 in MaybeT.HoistWriter(cxt, Maybe.JustIf(m, () => new Unit())) from _4 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 3"))) select 5; value = computation.Run; Assert.False(value.Result.HasValue); Assert.Equal(new[] { "function call 1", "function call 2" }, (IEnumerable <string>)value.State); }
HoistWriter <TOutput, TMonoid, TValue>( WriterCxt <TOutput, TMonoid> _cxt, Maybe <TValue> value) where TMonoid : IMonoid <TOutput> { var m = new MaybeT <Writer <TOutput, TValue, TMonoid>, Writer <TOutput, Maybe <TValue>, TMonoid>, Maybe <TValue>, TValue>(); return((MaybeT <Writer <TOutput, TValue, TMonoid>, Writer <TOutput, Maybe <TValue>, TMonoid>, Maybe <TValue>, TValue>)m.Hoist(value)); }