public static void LinqReaderTest() { var cxt = new ReaderCxt <Dictionary <int, int> >(); var computation = from x in MaybeT.Lift(cxt.Get()) from y in MaybeT.Lift(cxt.With(env => env[4])) from z in MaybeT.Lift(cxt.Local(dict => { var d2 = new Dictionary <int, int>(dict) { [99] = 150 }; return(d2); }, from u in cxt.Get() select u[99])) from _ in MaybeT.HoistReader(cxt, Maybe.JustIf(x.ContainsKey(120), () => new Unit())) select x[1] + y + z; var value = computation.Run.Run(new Dictionary <int, int> { { 1, 2 }, { 4, 8 }, { 16, 32 }, { 120, 0 } }); Assert.True(value.HasValue); Assert.Equal(2 + 8 + 150, value.Value()); value = computation.Run.Run(new Dictionary <int, int> { { 1, 2 }, { 4, 8 }, { 16, 32 } }); Assert.False(value.HasValue); }
HoistReader <TEnvironment, TValue>( ReaderCxt <TEnvironment> _cxt, Maybe <TValue> value) { var m = new MaybeT <Reader <TEnvironment, TValue>, Reader <TEnvironment, Maybe <TValue> >, Maybe <TValue>, TValue>(); return((MaybeT <Reader <TEnvironment, TValue>, Reader <TEnvironment, Maybe <TValue> >, Maybe <TValue>, TValue>)m.Hoist(value)); }