Beispiel #1
0
        public Task <char> Demo_WithUnitAndBind()
        {
            string      sentence   = "Hello world!";
            Task <char> charToFind = AsyncMonad.Unit('H');

            Task <char> divided = charToFind
                                  .Bind(chr => GetIndexOfCharacterAsync(sentence, chr))
                                  .Bind(index => GetCharacterAtIndexAsync(sentence, index));

            return(divided);
        }
Beispiel #2
0
        public Task <char> Demo_Linq()
        {
            string      sentence   = "Hello world!";
            Task <char> charToFind = AsyncMonad.Unit('H');

            Task <char> result =
                from chr in charToFind
                from index in GetIndexOfCharacterAsync(sentence, chr)
                from nextChar in GetCharacterAtIndexAsync(sentence, index)
                select nextChar;

            /* similar to 'do notation' Haskell...
             * do chr <- charToFind
             *    index <- GetIndexOfCharacter sentence chr
             *    nextChar <- GetCharacterAtIndex sentence index
             *    return nextChar
             */

            return(result);
        }