spartanz / schemaz

A purely-functional library for defining type-safe schemas for algebraic data types, providing free generators, SQL queries, JSON codecs, binary codecs, and migration from this schema definition
https://spartanz.github.io/schemaz
Apache License 2.0
164 stars 18 forks source link

WIP: Use traversal instead of hard coding Schema[List[A]] #9

Closed jdegoes closed 4 years ago

jdegoes commented 6 years ago

We have a schema for a list. But we can generalize this and use use a Traversal optic like the product (lens) and sum (prism) cases.

Something like this:

final case class ColSchema[A](seq: Collection[A, _]) extends Schema[A]

case class Collection[C, A](traversal: Traversal[C, A], element: Schema[A])

I think every optic type will have its own term in the Schema sum type to give us the greatest chances for powerful composition.

Note: this is not quite right because we would like the ability to not only just modify elements and retrieve them, but also set them.

jdegoes commented 6 years ago

It was suggested to me we can simply use a Lens for List[A]. Then the user can (via imap) support any other collection type which is isomorphic to a lens. And we can have different helpers for all of Scala's standard collections, as well as helpers for Scalaz data structures.