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

Monoid for Option[A], 10.2 #598

Open
minnieshi opened this issue Nov 18, 2020 · 0 comments
Open

Monoid for Option[A], 10.2 #598

minnieshi opened this issue Nov 18, 2020 · 0 comments

Comments

@minnieshi
Copy link

I think the answer for Monoid[Option[A]], by just using 'orElse' is too simplified, see below
def optionMonoid[A]: Monoid[Option[A]] = new Monoid[Option[A]] { def op(x: Option[A], y: Option[A]) = x orElse y val zero = None }

https://stackoverflow.com/a/43517616/4582240
https://typelevel.org/cats/typeclasses/monoid.html
has better implementation. i.e. it goes deeper into type A, to combine them. and requires A has a semiGroup instance, i.e. A has combine operation. (implicit sgA: Semigroup[A])

but my question is when would you use the 'orElse' approach implelmentation? Is it due to what kind of problem you are trying to solve?

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

No branches or pull requests

2 participants