Signature:
//trait Functor[F[_]]
def ifF[A](fb: F[Boolean])(ifTrue: A, ifFalse: A): F[A]
Similar to ifM from Monad, but doesn't flatten.
Will be closed by #3058
Shouldn't it go to the IfFunctorOps like it was done for Apply and FlatMap?
I think it could be either of these places. Both in the type class with a default implementation and in the syntax. Probably only in the syntax until we drop 2.11 support though.
That reads like "if and only if" :smile:
Should the branches be by-name though?
For laziness, they probably should, yeah.
Good point about the name, but it matches ifA and ifM.
Implementation in terms of map is ok?
def ifF[A](fb: F[Boolean])(ifTrue: A, ifFalse: A): F[A] = map(fb)(x => if(x) ifTrue else ifFalse)
I think so, everything in Functor will use map :D
What about comment of @joroKr21 regarding by-name parameters? I have hit a problem with the as once, by putting there quite heavy computation that was ran despite of the failed flow. I know it is probably corner case, but still, there is possibility to encounter it.
I agree these should be by-name, or in Eval. We can probably add the latter in the future if it seems like a nice thing to have.
I can see @vasiliybondarenko is working on this!
Could anybody review my solution?
Merged to master in #3058!
Most helpful comment
That reads like "if and only if" :smile:
Should the branches be by-name though?