Last active
August 29, 2015 14:04
-
-
Save mbrandonw/7f46100a6254425ab37f to your computer and use it in GitHub Desktop.
Monadic units with function overloading.
This file contains 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
func unit <A> (x: A) -> A? { | |
return Optional.Some(x) | |
} | |
func unit <A> (x: A) -> [A] { | |
return [x] | |
} | |
// hypothetical examples | |
func unit <A> (x: A) -> Tree<A> { | |
return Tree<A>(root: x) | |
} | |
func unit <A> (x: A) -> Future<A> { | |
return Future<A>(value: x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment