Beispiel #1
0
 public int CompareTo(Array1 <T> other) =>
 (Rest.Length == other.Rest.Length)
         ? ToEnumerable().Zip(
     other.ToEnumerable(),
     (a, b) =>
 {
     if (a is IComparable comparable)
     {
         return(comparable.CompareTo(b));
     }
     throw new Exception("Trying to compare Array1 based on non-comparable type " + typeof(T).ToString());
 }).SkipWhile(c => c == 0).Take(1).Sum()             // The SUM will get a 0 on full equality which is as you'd want
         : Rest.Length.CompareTo(other.Rest.Length);
Beispiel #2
0
        public Array1 <U> SelectMany <U>(Func <T, Array1 <U> > f)
        {
            return(Array1.Insist(ToEnumerable().SelectMany(x => f(x).ToEnumerable())));

/*
 *          Something wrong with this - was just an optimization anyway
 *          var fr0 = f(First);
 *
 *
 *          int totalLengthOfNewRest = fr0.Rest.Length;
 *
 *          // technically correct assumption in that every element in Rest has to provide at least 1 as F returns an Array1
 *          var rs = new Array1<U>[fr0.Rest.Length]; // new List<U>(fr0.Rest);
 *          {
 *              int currentIndex = 0;
 *              foreach (var s in Rest.Select(f))
 *              {
 *                  rs[currentIndex] = s;
 *                  totalLengthOfNewRest += s.Length;
 ++ currentIndex;
 ++             }
 ++         }
 ++
 ++         var fr0First = fr0.First;
 ++         var fr0Rest = fr0.Rest;
 ++         {
 ++             var r = new U[totalLengthOfNewRest];
 ++             int fr0RestLength = fr0Rest.Length;
 ++             Array.Copy(fr0Rest, 0, r, 0, fr0RestLength);
 ++             int currentIndex = fr0RestLength;
 ++
 ++             foreach (var g in rs)
 ++             {
 ++                 r[currentIndex] = g.First;
 ++ currentIndex;
 ++                 foreach (var v in g.Rest)
 ++                 {
 ++                     r[currentIndex] = v;
 ++ currentIndex;
 ++                 }
 ++             }
 ++
 ++             if (currentIndex != totalLengthOfNewRest)
 ++             {
 ++                 throw new Exception("Grave error in implementation of SelectMany - guess it hasn't been tested/used at all");
 ++             }
 ++
 ++             return new Array1<U>(fr0First, r);
 ++         }
 */
        }
Beispiel #3
0
 public static ProblemQualified <T> ForTerminal(Array1 <string> terminal, IEnumerable <string> nonTerminalWarnings) => new ProblemQualified <T>(Either <Array1 <string>, T> .FromLeft(terminal), nonTerminalWarnings);
Beispiel #4
0
 public static ProblemQualified <T> ForTerminal(string terminal) => new ProblemQualified <T>(Either <Array1 <string>, T> .FromLeft(Array1.Build(terminal)), Enumerable.Empty <string>());
Beispiel #5
0
 public void ReportTerminal(string terminal) => ReportTerminals(Array1.Build(terminal));
Beispiel #6
0
 public static TwinMap1 <TPrimaryKey, TSecondary, TValue> Build(Array1 <Tuple <TPrimaryKey, TSecondary, TValue> > entries) =>
 Map1.Build(entries.Select(x => Tuple.Create(x.Item1, Tuple.Create(x.Item2, x.Item3)))).Let(
     p =>
     new TwinMap1 <TPrimaryKey, TSecondary, TValue>(
         p,
         Map1.Insist(p.GetKeyValuePairs().Select(x => Tuple.Create(x.Item2.Item1, x.Item1)))));
Beispiel #7
0
 public Array1 <V> Zip <U, V>(Array1 <U> other, Func <T, U, V> f) => new Array1 <V>(f(First, other.First), Rest.Zip(other.Rest, f).ToArray());
Beispiel #8
0
 public bool Equals(Array1 <T> obj) => (Rest.Length == obj.Rest.Length) && ToEnumerable().Zip(obj.ToEnumerable(), (a, b) => a.Equals(b)).All(x => x);