These are chat archives for evhub/coconut

Jun 2018
Jun 20 2018 01:21 UTC
Since the wrapper will only call the wrapped function with a Right(value), the wrapped function doesn't really need to know about anything other than value (return fn(val) in your example).
Jun 20 2018 01:42 UTC
And I agree. Sans those two oddities, skip_error_path does look very similar to bind to me. Enough to make me wonder what a bind function in Coconut might look like.
data Left(error_msg):
    def __fmap__(self, _) = self
    def __join__(self) = self

data Right(result):
    def __join__(Right(Right(x))) = Right(x)
    def __join__(Right(Left(x))) = Left(x)

Either = (Left, Right)

def join(x) = x.__join__()
def bind(f, x) = join..fmap(f, x)
Actually pretty neat. I might start using this for my own code. Given @balajeerc's example, the calls would look something like... .
safe_halve(4) |> fmap$(sqrt) |> handle
safe_halve(5) |> fmap$(sqrt) |> handle
# and a contrived `bind` example...
Right(5) |> bind$(safe_halve) |> fmap$(sqrt) |> handle