Skip to content

Instantly share code, notes, and snippets.

@diversit
Created February 25, 2020 09:43
Show Gist options
  • Save diversit/8cf6ba39a5f67d24a6c57fdc2c16d839 to your computer and use it in GitHub Desktop.
Save diversit/8cf6ba39a5f67d24a6c57fdc2c16d839 to your computer and use it in GitHub Desktop.
Thrust operator to move monad conversion to right to get more readable code
package utils
/**
* From 'How to unsuck Future[Option[T]]' by Erik Bakker.
* Operator taken from Scalaz which allow to specify a function in a different order.
*
* This operator allows to move transformations in for-comprehension to the right
* which makes the code easier to read.
*/
object ThrushOperator {
implicit class ThrushOperator[A](val a: A) extends AnyVal {
def |>[B](f: A => B) = f(a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment