Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Last active August 29, 2015 14:04
Show Gist options
  • Save mbrandonw/7f46100a6254425ab37f to your computer and use it in GitHub Desktop.
Save mbrandonw/7f46100a6254425ab37f to your computer and use it in GitHub Desktop.
Monadic units with function overloading.
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