HoistState <TState, TValue>( StateCxt <TState> _cxt, Maybe <TValue> value) { var m = new MaybeT <State <TState, TValue>, State <TState, Maybe <TValue> >, Maybe <TValue>, TValue>(); return((MaybeT <State <TState, TValue>, State <TState, Maybe <TValue> >, Maybe <TValue>, TValue>)m.Hoist(value)); }
public static void LinqStateTest() { var cxt = new StateCxt <string>(); var computation = from x in MaybeT.Lift(cxt.Get()) from y in MaybeT.Lift(cxt.Put("xyz")) from z in MaybeT.Lift(cxt.Modify(s => x + "___")) from u in MaybeT.Lift(cxt.Get()) from _ in MaybeT.HoistState(cxt, Maybe.JustIf(x.Length >= 3, () => 1)) from v in MaybeT.Lift(cxt.Put("gef")) select u; var(value, state) = computation.Run.Run("abc"); Assert.True(value.HasValue); Assert.Equal("abc___", value.Value()); Assert.Equal("gef", state); (value, state) = computation.Run.Run("ab"); Assert.False(value.HasValue); Assert.Equal("ab___", state); }