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()); }
public Func <Unit, S> Fold <S>(Lst <A> fa, S state, Func <S, A, S> f) => _ => fa.Fold(state, f);
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);
private string FoldRow(Lst <Option <Shapes> > row) => row.Fold(new StringBuilder().Append("|"), (s, x) => s.Append(x.Match( Some: shape => $"{shape.ToString()}|", None: () => " |"))).ToString();