question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generic instances for value classes

See original GitHub issue

It 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
pjancommented, May 12, 2017

@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.

3reactions
melriefcommented, May 12, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found