Generic instances for value classes
See original GitHub issueIt would be great if these would make it to the library. Happy to open a PR for it, if somebody points me to the right place for these:
implicit def decoderValueClass[T <: AnyVal, V](
implicit
gen: Lazy[Generic.Aux[T, V :: HNil]],
decoder: Decoder[V]
): Decoder[T] = Decoder.instance { cursor ⇒
decoder(cursor).map { value ⇒
gen.value.from(value :: HNil)
}
}
implicit def encoderValueClass[T <: AnyVal, V](
implicit
gen: Lazy[Generic.Aux[T, V :: HNil]],
encoder: Encoder[V]
): Encoder[T] = Encoder.instance { value ⇒
encoder(gen.value.to(value).head)
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Generic Types - Learning the Java Language
Examples and practices described in this page don't take advantage of ... A generic type is a generic class or interface that is...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
Generics in Java with collection classes is very easy but it provides a lot more features than just creating the type of collection....
Read more >java - Using Generics to retrieve a list of classes of type Generic
The key can be any type, for example Integer.class; The value can be any type IChallenge<T> and if T is not Integer (or...
Read more >Generics in Java - GeeksforGeeks
Using Generics, it is possible to create classes that work with different data types. An entity such as class, interface, or method that ......
Read more >4.1. Generic Types - Java in a Nutshell, 5th Edition [Book]
Generic types and methods are the defining new feature of Java 5.0. A generic type is defined using one or more type variables...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Tvaroh not a discussion that we need to have here (I don’t want to highjack the conversation), but not everything needs to be heavily speed/memory optimized, and valueclasses can be beneficial as they can eliminate a whole class of developer bugs in environments where these can be particularly costly.
@Tvaroh nothing in this PR forces the developer to use value classes but for people who may want to use them this can be useful. I don’t think this is the right place to have a discussion about a feature of the Scala language.