Skip to content

Instantly share code, notes, and snippets.

@klgraham
Created March 26, 2016 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klgraham/3ddaeb82d33faf3a1547 to your computer and use it in GitHub Desktop.
Save klgraham/3ddaeb82d33faf3a1547 to your computer and use it in GitHub Desktop.
struct Distribution<A> {
var get: () -> A?
func sample(n: Int) -> [A] {
return (1...n).map { x in get()! }
}
func map<B>(f: A -> B) -> Distribution<B> {
var d = Distribution<B>(get: {() -> Optional<B> in return nil})
d.get = {
(Void) -> B in return f(self.get()!)
}
return d
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment