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); }
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); }
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); }