-
Notifications
You must be signed in to change notification settings - Fork 53
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 extractors #29
Comments
so in fact you want to create lenses, right? :) You could have: |
👍 for I also have a use case where that would be super convenient. Of course I could use Monocle, but I prefer the terse syntax of |
There's one major problem here unfortunately: when you are using e.g. A partial solution could be to constrain |
FWIW, in Monocle the things that can extract/modify several values at once (but not get a single value) are called Traversals. |
I think it's possible to come up with both a simple and powerful API here, but that might require making the implementation more complex. More concretely, I would suggest that |
@jedesah I would be against using whitebox macros, for two main reasons: they are not IDE-friendly (you don't know the return type until you actually run the compiler), and they won't be supported in the new scala-meta based macros (while you should be able to implement quicklens in its current form using scala meta) |
I'm using such code right now to have class QuckLensExt[T,U](private val pm: PathModify[T, U]) extends AnyVal {
def get = {
var values: List[U] = Nil
pm.using { x =>
values ::= x
x
}
values
}
}
even if introducing |
As we can't use:
as it's hard to analyze such complex AST, it would be great to have something like:
person.modify(_.address.street.name).get
Which will return a
List
of values. This will allow to reuse a path for both read and write.My practical need is to actually check a path at one instance of case class, but modify the same path in another instance of the same case class:
Currently, I've got to hack it with vars (or alternate the model), which is not very functional...
The text was updated successfully, but these errors were encountered: