示例#1
0
    public static HMap <A, HMap <B, HMap <C, HMap <D, T> > > > Remove <A, B, C, D, T>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, A aKey, B bKey, C cKey, D dKey)
    {
        var res = self.Find(aKey, bKey, cKey);

        if (res.IsSome && res.CountT() > 1)
        {
            return(self.SetItemT(aKey, bKey, cKey, res.Lift().Remove(dKey)));
        }
        else
        {
            if (res.IsSome)
            {
                if (res.MapT(d => d.ContainsKey(dKey)).Lift())
                {
                    return(Remove(self, aKey, bKey, cKey));
                }
                else
                {
                    return(self);
                }
            }
            else
            {
                return(Remove(self, aKey, bKey, cKey));
            }
        }
    }
示例#2
0
 public static R Find <A, B, C, D, T, R>(this HMap <A, HMap <B, HMap <C, HMap <D, T> > > > self, A aKey, B bKey, C cKey, D dKey, Func <T, R> Some, Func <R> None) =>
 self.Find(aKey,
           b => b.Find(bKey,
                       c => c.Find(cKey,
                                   d => d.Find(dKey, Some, None),
                                   None),
                       None),
           None);
示例#3
0
    public static HMap <A, HMap <B, HMap <C, HMap <D, V> > > > TrySetItemT <A, B, C, D, V>(this HMap <A, HMap <B, HMap <C, HMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            return(map);
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.TrySetItemT(bKey, cKey, dKey, Some)));
    }
示例#4
0
    public static HMap <A, HMap <B, V> > TrySetItemT <A, B, V>(this HMap <A, HMap <B, V> > map, A aKey, B bKey, V value)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            return(map);
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.TrySetItem(bKey, value)));
    }
示例#5
0
    public static HMap <A, HMap <B, HMap <C, HMap <D, V> > > > SetItemT <A, B, C, D, V>(this HMap <A, HMap <B, HMap <C, HMap <D, V> > > > map, A aKey, B bKey, C cKey, D dKey, Func <V, V> Some)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            throw new ArgumentException("Key not found in Map");
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.SetItemT(bKey, cKey, dKey, Some)));
    }
示例#6
0
    public static HMap <A, HMap <B, V> > SetItemT <A, B, V>(this HMap <A, HMap <B, V> > map, A aKey, B bKey, V value)
    {
        var a = map.Find(aKey);

        if (a.IsNone)
        {
            throw new ArgumentException("Key not found in Map");
        }
        var av = a.Value;

        return(map.SetItem(aKey, av.SetItem(bKey, value)));
    }
示例#7
0
    public static HMap <A, HMap <B, T> > Remove <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey)
    {
        var b = self.Find(outerKey);

        if (b.IsSome)
        {
            var bv = b.Value.Remove(innerKey);
            if (bv.Count() == 0)
            {
                return(self.Remove(outerKey));
            }
            else
            {
                return(self.SetItem(outerKey, bv));
            }
        }
        else
        {
            return(self);
        }
    }
示例#8
0
    public static HMap <A, HMap <B, HMap <C, T> > > Remove <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey)
    {
        var b = self.Find(aKey);

        if (b.IsSome)
        {
            var c = b.Value.Find(bKey);
            if (c.IsSome)
            {
                var cv = c.Value.Remove(cKey);
                if (cv.Count() == 0)
                {
                    var bv = b.Value.Remove(bKey);
                    if (b.Value.Count() == 0)
                    {
                        return(self.Remove(aKey));
                    }
                    else
                    {
                        return(self.SetItem(aKey, bv));
                    }
                }
                else
                {
                    return(self.SetItem(aKey, b.Value.SetItem(bKey, cv)));
                }
            }
            else
            {
                return(self);
            }
        }
        else
        {
            return(self);
        }
    }
示例#9
0
 public static R Find <A, B, T, R>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey, Func <T, R> Some, Func <R> None) =>
 self.Find(outerKey, b => b.Find(innerKey, Some, None), None);
示例#10
0
 public static Option <T> Find <A, B, C, T>(this HMap <A, HMap <B, HMap <C, T> > > self, A aKey, B bKey, C cKey) =>
 self.Find(aKey, b => b.Find(bKey, c => c.Find(cKey), () => None), () => None);
示例#11
0
 public static Option <T> Find <A, B, T>(this HMap <A, HMap <B, T> > self, A outerKey, B innerKey) =>
 self.Find(outerKey, b => b.Find(innerKey), () => None);