-
Notifications
You must be signed in to change notification settings - Fork 63
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
implement Cats typeclass instances for Ask and Local #465
Conversation
this lets users map (or imap, for Local) the environment of a given instance and make the mapped value available in a new implicit scope
Interesting. I was thinking about your |
I have a vague memory of suggesting similar sorts of instances in the past, but I'm having trouble finding those PRs. Maybe it was in chat, not sure. I don't remember there being specific reasons not to do it, mostly just "huh that's different". But it's been a while; maybe I'm misremembering. I considered just adding the Implementing this way also lets us take advantage of the laws, which would be harder to test otherwise. Now that I think about it, that actually might be the stronger argument for doing it this way. 🙂 |
Do the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I really like this idea!
This lets users
map
/flatMap
(forAsk
) orimap
(forLocal
) the environment of a given instance and make the mapped value available in a new implicit scope.This came up for me when trying to provide a
Local[F, natchez.Span[F]]
, whereF[_]
isKleisli[IO, Span[IO], *]
.Local.baseLocalForKleisli
gives usLocal[Kleisli[IO, Span[IO], *], Span[IO]]
, which is not quite the right shape for an app with animplicit ev: Local[F, Span[F]]
(which becomesev: Local[Kleisli[IO, Span[IO], *], Span[Kleisli[IO, Span[IO], *]]]
). In other words,baseLocalForKleisli
gives us a local environment ofSpan[IO]
when we needSpan[Kleisli[IO, Span[IO], *]]
.Given
Invariant[Local[F, *]]
, we can doto get the
Local[Kleisli[IO, Span[IO], *], Span[Kleisli[IO, Span[IO], *]]]
needed for the app.