Skip to content

Commit

Permalink
Merge pull request #6 from narma/add_reads_helper_method
Browse files Browse the repository at this point in the history
add Reads.derive method
  • Loading branch information
narma authored Jul 12, 2022
2 parents 65b7721 + cb46be2 commit 9651c76
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/scala/zio/cassandra/session/cql/codec/Reads.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ object Reads extends ReadsInstances1 {

def instance[T](f: Row => T): Reads[T] = (row: Row) => f(row)

/** Useful when you want to "cache" [[zio.cassandra.session.cql.codec.Reads]] instance (e.g. to decrease compilation
* time or make sure it captures the correct [[zio.cassandra.session.cql.codec.Configuration]])
*
* Example:
* {{{
* final case class Foo(a: Int, b: String)
*
* // somewhere else
* implicit val configuration: Configuration = {
* val renameFields: String => String = {
* case "a" => "some_other_name"
* case other => Configuration.snakeCaseTransformation(other)
* }
* Configuration(renameFields)
* }
*
* implicit val reads: Reads[Foo] = Reads.derive
* }}}
*/
def derive[T, Repr](implicit
configuration: Configuration,
gen: LabelledGeneric.Aux[T, Repr],
reads: Reads[Repr]
): Reads[T] = genericReads

}

trait ReadsInstances1 extends ReadsInstances2 {
Expand Down

0 comments on commit 9651c76

Please sign in to comment.