public static void LinqRwsTest() { var cxt = new RwsCxt <Dictionary <int, int>, IList <string>, Monoid.ListAppendImmutableMonoid <string>, int>(); var computation = from x in MaybeT.Lift(cxt.Get()) from _1 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 1"))) from _2 in MaybeT.Lift(cxt.Put(x + 3)) from env in MaybeT.Lift(cxt.GetEnvironment()) from _3 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 2"))) from twice in MaybeT.HoistRws(cxt, Maybe.JustIf(env.ContainsKey(x), () => env[x])) from _4 in MaybeT.Lift(cxt.Tell(FuncList.Make("function call 3"))) from _5 in MaybeT.Lift(cxt.Put(x + 10)) from y in MaybeT.Lift(cxt.Get()) from _6 in MaybeT.Lift(cxt.Put(y + x)) from goodKey in MaybeT.HoistRws(cxt, Maybe.Just(1)) select x + twice; var(value, state, output) = computation.Run.Run(new Dictionary <int, int> { { 1, 2 }, { 4, 8 }, { 16, 32 } }, 16); Assert.True(value.HasValue); Assert.Equal(16 + 32, value.Value()); Assert.Equal(16 + 26, state); Assert.Equal(new[] { "function call 1", "function call 2", "function call 3" }, (IEnumerable <string>)output); (value, state, output) = computation.Run.Run(new Dictionary <int, int> { { 1, 2 }, { 4, 8 }, { 16, 32 } }, 17); Assert.False(value.HasValue); Assert.Equal(20, state); Assert.Equal(new[] { "function call 1", "function call 2" }, (IEnumerable <string>)output); }
HoistRws <TEnvironment, TOutput, TMonoid, TState, TValue>( RwsCxt <TEnvironment, TOutput, TMonoid, TState> _cxt, Maybe <TValue> value) where TMonoid : IMonoid <TOutput> { var m = new MaybeT <Rws <TEnvironment, TOutput, TMonoid, TState, TValue>, Rws <TEnvironment, TOutput, TMonoid, TState, Maybe <TValue> >, Maybe <TValue>, TValue>(); return((MaybeT <Rws <TEnvironment, TOutput, TMonoid, TState, TValue>, Rws <TEnvironment, TOutput, TMonoid, TState, Maybe <TValue> >, Maybe <TValue>, TValue>)m.Hoist(value)); }