Skip to content

Instantly share code, notes, and snippets.

@hgiddens
Created September 10, 2012 07:22
Show Gist options
  • Select an option

  • Save hgiddens/3689404 to your computer and use it in GitHub Desktop.

Select an option

Save hgiddens/3689404 to your computer and use it in GitHub Desktop.
Help!
// 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