Skip to content
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

derivation for generic Map case class field? #1

Open
evbo opened this issue Sep 4, 2022 · 0 comments
Open

derivation for generic Map case class field? #1

evbo opened this issue Sep 4, 2022 · 0 comments

Comments

@evbo
Copy link

evbo commented Sep 4, 2022

Hi, thanks for this boost getting started with type class derivation! I have a product case classes with various Map types and of course I can easily define a derive for each higher order kind, such as:

// not too too bad...
given mapRandIntStr: Random[Map[Int, String]] with { def produce: Map[Int, String] = Map(0 -> "test") }

// if only it were this easy....
given mapRand[K: Random, V: Random]: Random[Map[K, V]] = Random.derived

I understand Map type isn't really a (nested) product, and so you'd probably have to get at the underlying list of Tuple in order to properly derive it (actually this is mentioned subtly here). At the same time, writing a given for every single variation of Map[K,V] is a bit nightmare-ish too!

Do you have any thoughts on how this could be done, treating Map[K,V] as a nested Random as succinctly as possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant