Closed EarthyOrange closed 5 years ago
bimap
is more related to the map
function (where map
is a functor, bimap
is a bifunctor), so the current behaviour is the expected behaviour. You can see it from the types:
map :: Functor f => (f a) . (a -> b) -> f b
bimap :: Bifunctor f => (f a b) . (a -> c, b -> d) -> f c d
So each function takes in a value from inside the functor (or bifunctor in this case), transforms it, and the operation repackages that into a new functor (or bifunctor).
What's your use case? If you need to operate at the container level, but branching depending on the state of the container, you could try using the .matchWith
operation:
Result.error('error').matchWith({
Error: (x) => /* do something with the container x */,
Ok: (x) => /* do something with the container x */
});
Other than that, I don't think we have many operations on the container. It's not something I've missed personally, but maybe you have a different use case.
The bimap function unwraps the value present in the Result container, before passing it to the left or right functions.
Steps to reproduce
Expected behaviour
It should pass the container, as is, to the left or right function.
Environment