Last active
August 29, 2015 14:05
-
-
Save berrytj/e83e56a52f1737e7ac5a to your computer and use it in GitHub Desktop.
Curried
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
from __future__ import division | |
from funcy.curried import * | |
from fn import _ as __ | |
from bookends import _ | |
import survey | |
def total_probability((outcome, pmf)): | |
return (_| pmf | |
| select_keys(__ == outcome) | |
| __.values | |
| call | |
| sum | |
|_) | |
def prglength_pmf(records): | |
return (_| records | |
| count_by(__.prglength) | |
| walk_values(__ / len(records)) | |
|_) | |
@curry | |
def born_on_or_after(records, week): | |
return filter(__.prglength >= week, | |
records) | |
def main(): | |
births = survey.read_records() | |
outcomes = range(60) | |
prglength_groups = map(born_on_or_after(births), | |
outcomes) | |
print (_| prglength_groups | |
| map(prglength_pmf) | |
| partial(zip, outcomes) | |
| map(total_probability) | |
|_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment