public static Shrub <T2> Collapse <T2>(Shrub <Shrub <T2> > input) { return(input.Match <Shrub <T2> >( l => Shrub <T2> .Node(l.Select(Collapse <T2>).ToList()), v => v.Match(Shrub <T2> .Node, Shrub <T2> .Leaf) )); }
public Shrub <T2> Map <T2>(Func <T, T2> f) { return(Match( l => Shrub <T2> .Node(l.Select(s => s.Map <T2>(f)).ToList()) , v => Shrub <T2> .Leaf(f(v)))); }
public Shrub <T2> MapI <T2>(List <int> p, Func <T, List <int>, T2> f) { return(Match( l => Shrub <T2> .Node(l.Select((s, i) => s.MapI <T2>(p.Append(i).ToList(), f)).ToList()) , v => Shrub <T2> .Leaf(f(v, p)))); }
public Shrub <T> Insert(List <int> path, Shrub <T> sub_shrub) { return(ApplyAt(s => s.Match <Shrub <T> >(L => { L = L.ToList(); L.Insert(path.Last(), sub_shrub); return Node(L); }, x => throw new IndexOutOfRangeException()) , path.Take(path.Count - 1).ToList())); }
public bool Equal(Shrub <T> input) { return(Match <bool>(l1 => input.Match <bool>(l2 => { if (l1.Count != l2.Count) { return false; } for (int i = 0; i < l1.Count; i++) { if (!l1[i].Equal(l2[i])) { return false; } } return true; }, s2 => false), s1 => input.Match <bool>(l2 => false , s2 => s1.Equals(s2)))); }
public Shrub <T> Update(Shrub <T> s, List <int> path) { return(ApplyAt(_ => s, path)); }