Created
March 26, 2016 04:34
-
-
Save klgraham/3ddaeb82d33faf3a1547 to your computer and use it in GitHub Desktop.
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
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