Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CorentinClabaut opened this issue Aug 5, 2022 · 3 comments · May be fixed by #7
Open

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

CorentinClabaut opened this issue Aug 5, 2022 · 3 comments · May be fixed by #7

Comments

@CorentinClabaut
Copy link
Contributor

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 CorentinClabaut linked a pull request Aug 5, 2022 that will close this issue
@civilizeddev
Copy link

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.

@vikstrous2
Copy link

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?

@taman9333
Copy link
Contributor

@CorentinClabaut @civilizeddev @vikstrous2
Fold Can do this functionality & it runs against Result, Either & Option monads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants