Skip to content

Instantly share code, notes, and snippets.

@asflierl
Created July 24, 2018 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asflierl/7da0a53ce65fc9ca7a1e90a138fad2e2 to your computer and use it in GitHub Desktop.
Save asflierl/7da0a53ce65fc9ca7a1e90a138fad2e2 to your computer and use it in GitHub Desktop.
just another day in Scala...
private type H[A <: BSONValue, B] = BSONHandler[A, B]
private type DH[A] = BSONDocumentHandler[A]
object Implicits extends BSONConverter with DaoToDocDerivation {
private implicit def `(A, B) <-> BSON`[A <: BSONValue, B, C <: BSONValue, D](implicit hab: H[A, B], hcd: H[C, D]): DH[(B, D)] = handler[Tuple2[B, D]]
private implicit def `Coll[A] <-> BSON`[A[_], B](implicit h: H[_ <: BSONValue, B], cbf: CanBuildFrom[A[_], B, A[B]], ev: A[B] <:< Traversable[B]): H[BSONArray, A[B]] =
BSONHandler(bsonArrayToCollectionReader[A, B].read, collectionToBSONArrayCollectionWriter[B, A[B]].write)
private implicit def `Map[A, B] <-> BSON`[A, B](implicit htab: DH[(A, B)]): H[BSONArray, Map[A, B]] =
`Coll[A] <-> BSON`[Vector, (A, B)].as(_.toMap, _.toVector)
private implicit def `Set[A] <-> BSON`[A](implicit htab: H[_ <: BSONValue, A]): H[BSONArray, Set[A]] =
`Coll[A] <-> BSON`[Set, A]
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment