mo icon indicating copy to clipboard operation
mo copied to clipboard

Add Helper function that would work like Either.Match but would return another type

Open CorentinClabaut opened this issue 2 years ago • 3 comments

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.

CorentinClabaut avatar Aug 05 '22 06:08 CorentinClabaut

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.

civilizeddev avatar Dec 10 '22 00:12 civilizeddev

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?

vikstrous2 avatar Mar 26 '24 15:03 vikstrous2