Esempio n. 1
0
        public override string ToString()
        {
            var builder = Cells.Fold(
                new StringBuilder().AppendLine("------------------"),
                (s, x) => s.AppendLine(FoldRow(x))
                ).AppendLine("------------------");

            if (Status == GameStatus.Over)
            {
                WinnerShape.Match(
                    Some: s => builder.AppendLine($"GAME OVER! {s} wins!"),
                    None: () => builder.AppendLine("GAME OVER! Nobody wins!")
                    );
            }

            return(builder.ToString());
        }
Esempio n. 2
0
 public Func <Unit, S> Fold <S>(Lst <A> fa, S state, Func <S, A, S> f) => _ =>
 fa.Fold(state, f);
Esempio n. 3
0
 static Lst <IHaveName> MakeUnique(Lst <IHaveName> items) => items.Fold(
     Lst <IHaveName> .Empty,
     (lst, p) => lst.Add(lst.Contains(p, NameEquality) ? p.Set(x => x.Name = $"{x.Name}2") : p)
     );
 static int Product(Lst <NonEmpty, int> list) =>
 list.Fold(1, (s, x) => s * x);
Esempio n. 5
0
 private string FoldRow(Lst <Option <Shapes> > row) =>
 row.Fold(new StringBuilder().Append("|"),
          (s, x) => s.Append(x.Match(
                                 Some: shape => $"{shape.ToString()}|",
                                 None: () => " |"))).ToString();