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 empty to State and StateT objects #2294

Closed
wants to merge 1 commit into from

Conversation

sderosiaux
Copy link

Hi,

I had some States where I needed to deal with empty values, such as:

def orEmpty[F[_]: MonadError[?[_], Unit]: SemigroupK, A: Monoid](s: Parser[F, A]) =
    s <+> StateT.pure(Monoid[A].empty)

In order to be explicit, why not add a empty constructor using a Monoid[A] that calls pure behind the scene? Note that IndexedStateT has runEmpty variants with the same Monoid[A] logic.

If you think it's an API overhead, feel free to discard and close the PR, no worry.

@kailuowang
Copy link
Contributor

Could this be written as s <+> A.emtpy.pure? Finger crossed that ScalaC can infer the type.

@sderosiaux
Copy link
Author

@kailuowang No, I get diverging and ambiguous implicits (cats.implicits._). It works with s <+> Monoid[A].empty.pure[Parser[F, ?]] (which is the inverse notation of my initial example).

@kailuowang
Copy link
Contributor

yeah, unfortunately, scalac fails on inferring higher kinded types.

@larsrh
Copy link
Contributor

larsrh commented Sep 25, 2018

Rebased in #2533.

@larsrh larsrh closed this Sep 25, 2018
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 this pull request may close these issues.

3 participants