mo
mo copied to clipboard
Add Helper function that would work like Either.Match but would return another type
Could we have a helper function like the following for Either
?
func Map[T any](e Either[L, R], onLeft func(L) T, onRight func(R) T) T
It would be useful to be able to Map an Either to another type.
I also want there:
func Map[T, R any](a Functor[T], f func(value T) R) Functor[R]
func Ap[T, R any](a Applicative[T], ff Applicative[func(value T) R]) Applicative[R]
func FlatMap[T, R any](a Monad[T], f func(value T) Monad[R]) Monad[R]
But I'm not sure these can be implemented in Go.
I would love to have this function too. Was thinking that the name "Merge" could also describe it well, but maybe it's called map in other languages? 🤷 What does haskel call it?