예제 #1
0
 private static WBT <Pair <k, v> > .N Alter(Func <k, Ord> p, k key, Func <Opt <v>, Opt <v> > f, WBT <Pair <k, v> > .N t) =>
 WBT <Pair <k, v> > .Tip(t)
         ? (f(Ctors.None())).Case(_ => WBT <Pair <k, v> > .Tip(), (v vv) => WBT <Pair <k, v> > .Singleton(Ctors.Pair(key, vv)))
         : (p(t.v.Left()).Case(
                _ => WBT <Pair <k, v> > .Balance(t.v, Alter(p, key, f, t.l), t.r),
                _ => f(Ctors.Some(t.v.Right())).Case(
                    __ => WBT <Pair <k, v> > .Glue(t.l, t.r),
                    vv => WBT <Pair <k, v> > .Bin(t.s, Ctors.Pair(key, vv), t.l, t.r)),
                _ => WBT <Pair <k, v> > .Balance(t.v, t.l, Alter(p, key, f, t.r))));
예제 #2
0
 public static Opt <a> Lookup(Func <a, Ord> p, N t) => Tip(t) ? Ctors.None() : p(t.v).Case(_ => Lookup(p, t.l), _ => Ctors.Some(t.v), _ => Lookup(p, t.r));