Skip to content

Instantly share code, notes, and snippets.

@negator
Last active December 10, 2015 02:19
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 negator/4366999 to your computer and use it in GitHub Desktop.
Save negator/4366999 to your computer and use it in GitHub Desktop.
/*Enumeratee to manage writing to the file writer. Mapping any errors to Left*/
type ErrorOrActivity = Either[Error,Activity]
def fileWriting: Enumeratee[Activity, ErrorOrActivity] = {
/* writeToFile returns a Promise, but the Enumeratee type constraint
* does not expect a Promise. flatMap will return an
* Enumeratee[Activity,ErrorOrActivity] given a function from Activity
* to Promise[ErrorOrActivity].
*/
KloutEnumeratee.flatMap[ErrorOrActivity] { activity=>
writeToFile(activity.json).map{
case e @ Failure(_) => Left(e)
case _ => Right(activity)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment