Pipe Operator
Pipe operators provide a way to chain the functions in the context which may not supply map, antThen, or compose methods.
import com.twitter.inject.Logging
object PipeOperator extends Logging {
implicit class Pipe[T](val v: T) extends AnyVal {
def |>[U](f: T => U): U = f(v)
def $$[U](f: T => U): T = {
f(v); v
}
def #!(str: String = ""): T = {
debug(s"$str:$v"); v
}
}
}
-
|>operator works very similar asmapfunction. The context may not retain due to the return type off. -
$$execute the function application off, but return the original inputv. So it can compose with impure functions but still remain the original value for next chaining call without bothering inputv. -
#!is for logging.