You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here GenContains[User](_.id) must go through all the direct subtypes of User and verify that GenContains(_.id) resolves to lens. Example of generated tree:
valregisteredC=GenContains[Registered](_.id)
valanonymousC=GenContains[Anonymous](_.id)
newContains[User, String] {
defset(s: User, b: String) = s match {
caser: Registered=> registeredC.set(r, b)
casea: Anonymous=> anonymousC.set(a, b)
}
defextract(s: User):String= s match {
caser: Registered=> registeredC.extract(r)
casea: Anonymous=> anonymousC.extract(a)
}
}
The proposed solution should work even for the case when path is longer that one field, or one of the direct subtypes is a sealed family itself
2. Typeclass based sealed Contains derivation
Ability to derive Contains when each alternative has implicit Contains to the given type.
In the best form it should support recursion and GADTs
implicitdefvalidatedPath[A]:Contains[ValidatedField[A], Path] = {
newContains[ValidatedField[A], Path] {
defset(s: ValidatedField[A], b: Path):ValidatedField[A] = s match {
caser: Read=>Contains[Read, Path].set(r, b)
casec: Check[x, A] =>Contains[Check[x, A], Path].set(c, b)
}
defextract(s: ValidatedField[A]):Path= s match {
caser: Read=>Contains[Read, Path].extract(r)
casec: Check[x, A] =>Contains[Check[x, A], Path].extract(c)
}
}
}
3. Typeclass based case class to case class derivation
When two case classes have fields related to each other, sometimes we can derive Contains for them. Such case could be a partial replacement for complex data transformation libraries such as https://github.com/scalalandio/chimney
We will derive Contains[A, B] when :
Each field in B has a field with the same name in the A
For any two fields with the same name of types AF and BF we have AF =:= BF or Contains[AF, BF]
Latter could be relaxed providing implicit `Contains[A, A] during derivation
I'd like to have more
Contains
macro generators, covering common use cases.Few come to mind:
1. A sealed family form for
GenContains
example:
Here
GenContains[User](_.id)
must go through all the direct subtypes ofUser
and verify thatGenContains(_.id)
resolves to lens. Example of generated tree:The proposed solution should work even for the case when path is longer that one field, or one of the direct subtypes is a sealed family itself
2. Typeclass based sealed Contains derivation
Ability to derive Contains when each alternative has implicit
Contains
to the given type.In the best form it should support recursion and GADTs
latter should be expanded to
3. Typeclass based case class to case class derivation
When two case classes have fields related to each other, sometimes we can derive
Contains
for them. Such case could be a partial replacement for complex data transformation libraries such as https://github.com/scalalandio/chimneyWe will derive
Contains[A, B]
when :B
has a field with the same name in theA
AF
andBF
we haveAF =:= BF
orContains[AF, BF]
Latter could be relaxed providing implicit `Contains[A, A] during derivation
last line should be expanded to the following
The text was updated successfully, but these errors were encountered: