Created
November 12, 2016 23:23
-
-
Save artur-s/93b2c151ff5f86ff5c857d106b49a076 to your computer and use it in GitHub Desktop.
An example of Kleisli composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of Kleisli composition | |
let (>>=) m f = Option.bind f m | |
let (>=>) mf mg = fun x -> mf x >>= mg | |
let tryParseInt s = | |
match System.Int32.TryParse s with | |
| true, v -> Some v | |
| _ -> None | |
let name = function | |
| 0 -> Some "zero" | |
| 1 -> Some "jeden" | |
| 2 -> Some "dwa" | |
| _ -> None | |
let nameHead = List.tryHead >=> tryParseInt >=> name | |
nameHead [] | |
nameHead ["x";"123";"789"] | |
nameHead ["2";"123";"789"] | |
nameHead ["123";"456";"789"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment