-
Notifications
You must be signed in to change notification settings - Fork 521
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 Ref.lens constructor #827
Conversation
Some discussion on Gitter about the semantics (changes to A that don't involve changes in B): https://gitter.im/typelevel/cats-effect-dev?at=5e8b0e65d021c45cc7c995a6 |
I was looking at https://github.com/oleg-py/meow-mtl recently and I believe it covers your use case. It will both derive a Of course |
@rkrzewski we're using meow-mtl as well, the problem is that |
@djspiewak @SystemFw thoughts? I think this belongs here, but I remember you had different opinions on it |
On balance, I like it and I'd like to see it included |
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 like it.
@@ -226,6 +226,23 @@ object Ref { | |||
*/ | |||
def unsafe[F[_], A](a: A)(implicit F: Sync[F]): Ref[F, A] = new SyncRef[F, A](new AtomicReference[A](a)) | |||
|
|||
/** | |||
* Creates an instance focused on a component of another Ref's value. |
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 think we should briefly mention that updates in the parent that don't change the child won't disable the setter in the child's access
.
Hey @djspiewak, any chance we can release this soon? |
I find
Ref.lens
useful in tests, where a singleRef
aggregating state of multiple mocks can be transformed into a few "focused"Refs
, ready for use in the mocks.I'm not sure, though, if it should be a part of
cats-effect
or rather some small satellite library, so I'll leave it up to you to decide 😉