Skip to content

Instantly share code, notes, and snippets.

@sam
Last active August 26, 2016 22:04
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 sam/739633f616c57ae312e7cc377443e183 to your computer and use it in GitHub Desktop.
Save sam/739633f616c57ae312e7cc377443e183 to your computer and use it in GitHub Desktop.
A trivial, common example and for-comprehensions failing at it.
// fold
client ! Projects(rows.headOption.fold(Nil)(_ \ "value" extract))
// map.getOrElse
client ! Projects(rows.headOption
.map(_ \ "value" extract)
.getOrElse(Nil))
// Option.toList
client ! Projects(rows.headOption.toList.map(_ \ "value" extract))
// for-comprehension
client ! Projects(for { head <- rows.headOption.toList } yield head \ "value" extract)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment