Ejemplo 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());
        }
Ejemplo n.º 2
0
 public Func <Unit, S> Fold <S>(Lst <A> fa, S state, Func <S, A, S> f) => _ =>
 fa.Fold(state, f);
Ejemplo 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)
     );
Ejemplo n.º 4
0
 static int Product(Lst <NonEmpty, int> list) =>
 list.Fold(1, (s, x) => s * x);
Ejemplo 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();