Created
September 10, 2012 07:22
-
-
Save hgiddens/3689404 to your computer and use it in GitHub Desktop.
Help!
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
| // init guaranteed to be non-empty | |
| // Basically this is trying to take a paginated response of Ts and turn it into a non-paginated list of all the Ts. | |
| val init: M[List[T]] // guaranteed to be non-empty | |
| val last: List[T] => T // does what it says on the tin | |
| val continue: T => Option[S] // given a response T, returns the key necessary to retrieve the next page | |
| val next: S => M[T] // given a key, retrieves the next page | |
| ... | |
| combine: (List[T], M[T]) => M[List[T]] | |
| def iterate(v: M[List[T]]): M[List[T]] = | |
| v.map { ts => | |
| continue(last(ts)).fold( | |
| s => next(s).map(ss => iterate(combine(ts, ss))), | |
| point[M](ts) // I've forgotten the actual syntax. | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment