Exemplo n.º 1
0
        public static Option <int> Demo_WithUnitAndBind()
        {
            Option <string> input = OptionMonad.Unit("asdfasdf");

            Option <int> divided = input
                                   .Bind(number => ParseIntOptional(number))
                                   .Bind(parsed => DivideByOptional(parsed, 2));

            return(divided);
        }
Exemplo n.º 2
0
        public static Option <int> Demo_WithUnitAndBind_Linq()
        {
            Option <string> input = OptionMonad.Unit("24");

            Option <int> result =
                from number in input
                from parsed in ParseIntOptional(number)
                from divided in DivideByOptional(parsed, 2)
                select divided;

            return(result);
        }
Exemplo n.º 3
0
        public static Option <char> Demo_WithNextChar_Linq()
        {
            Option <char> input    = OptionMonad.Unit('H');
            const string  sentence = "Hello World!";

            Option <char> result =
                from chr in input
                from index in GetIndexOfCharacter(sentence, chr)
                from nextChar in GetCharacterAtIndex(sentence, index + 1)
                select nextChar;

            return(result);
        }