What is the purpose of *> and <* in Scalaase
This is the syntax
. I recently added a few examples of the syntax to apply subproject examples scalaz, you can see specific discussion
The idea is that you evaluate two "efficient" computations on either side of the combinator, using an Apply instance to combine the effects, but discarding one of the resulting values.
throws out the value on the right and
throws out the value on the left.
In your example, we use Apply [Future] to combine the effects, and the effect is deferred evaluation of the future. In the first case, we get the following match:
f(Some(e)).get *> Future.now(-\/(e))
wraps, when we apply the function
, this task is done only for its side effects. The right half of the app
is the value we want to return, in
, but we want this future to depend on the result of the side effect
. As a result, we get a
, but it won't be complete until the side effect completes.
I think parser combinators are a good example of how these combinators are easy to understand. Let's assume we have some kind of parser:
This is what will consume some input and produce A in the process. Let's say we have a method that will parse a symbol:
def chr(c: Char): Parser[Char]
and some method that will parse an arbitrary string:
def foo: Parser[String]
then we can make a parser for our arbitrary string in parentheses:
val parentheticalFoo: Parser[String] = chr('(') *> foo <* chr(')')
this creates a parser that, although it will use an open parenthesis, then foo, then close the parentheses, it will only return the result of parsing foo. We don't care about actually receiving the output of the pairs
, but we want their input consumption effects to still be merged into the resulting parser.