Beispiel #1
0
 private static Zen <FiniteString> At(Zen <IList <ushort> > s, Zen <ushort> i, int current)
 {
     return(s.Case(
                empty: FiniteString.Empty(),
                cons: (hd, tl) =>
                If(i == (ushort)current, FiniteString.Singleton(hd), At(tl, i, current + 1))));
 }
Beispiel #2
0
 private static Zen <bool> StartsWith(Zen <IList <ushort> > s, Zen <IList <ushort> > pre)
 {
     return(pre.Case(
                empty: true,
                cons: (hd1, tl1) => s.Case(
                    empty: false,
                    cons: (hd2, tl2) => AndIf(hd1 == hd2, StartsWith(tl2, tl1)))));
 }
Beispiel #3
0
 private static Zen <Option <ushort> > IndexOf(Zen <IList <ushort> > s, Zen <IList <ushort> > sub, int current)
 {
     return(s.Case(
                empty: If(sub.IsEmpty(), Some <ushort>((ushort)current), Null <ushort>()),
                cons: (hd, tl) => If(StartsWith(s, sub), Some <ushort>((ushort)current), IndexOf(tl, sub, current + 1))));
 }
Beispiel #4
0
 private static Zen <bool> Contains(Zen <IList <ushort> > s, Zen <IList <ushort> > sub)
 {
     return(s.Case(
                empty: sub.IsEmpty(),
                cons: (hd, tl) => OrIf(StartsWith(s, sub), Contains(tl, sub))));
 }