Esempio n. 1
0
        public static ConsList <T> Nil()
        {
            var list = new ConsList <T>();

            list.variant = Variant <Unit, Tuple <T, ConsList <T> > > .C1(Unit.New());

            return(list);
        }
Esempio n. 2
0
        public static Option <T> None()
        {
            //このへんがダサい
            var option = new Option <T>();

            option.variant = Variant <Unit, T> .C1(Unit.New());

            return(option);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Variant生のまま");
            var foo = new[] {
                Variant <int, string> .C1(4),
                Variant <int, string> .C2("foo")
            };

            foo
            .ForEach(either => either
                     .Match(
                         C1: i => i.ToString(),
                         C2: s => s)
                     .Act(Console.WriteLine));

            //Option<T> = Variant<Unit,T>
            Console.WriteLine("\nOption");
            var hoge = new[] {
                Option <int> .None(),
                Option <int> .Some(10)
            };

            hoge
            .ForEach(opt => opt.
                     Match(
                         None: () => - 1,
                         Some: v => v)
                     .Act(Console.WriteLine));

            //ConsList<T> = Variant<Unit,Tuple<T,ConsList<T>>>
            Console.WriteLine("\nConsList");
            var list = new[] { 2, 3, 5, 8, 12 }.ToConsList();

            list
            .Match(
                Nil: () => 0,
                Cons: (head, tail) => head)
            .Act(Console.WriteLine);

            //Sum
            list
            .Catamorphism(
                nil: () => 0,
                cons: (h, t) => h + t)
            .Act(Console.WriteLine);

            Console.ReadLine();
        }
Esempio n. 4
0
 public static Either <TLeft, TRight> Left(TLeft left)
 {
     return(new Either <TLeft, TRight>(Variant <TLeft, TRight> .C1(left)));
 }
Esempio n. 5
0
 internal static ConsList <T> Nil()
 {
     return(new ConsList <T>(Variant <Product, Product <T, ConsList <T> > > .C1(Product.Create())));;
 }
Esempio n. 6
0
 public static Option <T> Some(T value)
 {
     return(new Option <T>(Variant <T, Product> .C1(value)));
 }