All Downloads are FREE. Search and download functionalities are using the official Maven repository.

doobie.postgres.TextPlatform.scala Maven / Gradle / Ivy

// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.postgres

import shapeless.{HList, HNil, ::, Generic, Lazy}

trait TextPlatform { this: Text.type =>

  // HNil isn't a valid Text but a single-element HList is
  implicit def single[A](
      implicit csv: Text[A]
  ): Text[A :: HNil] =
    csv.contramap(_.head)

  // HLists of more that one element
  implicit def multiple[H, T <: HList](
      implicit
      h: Text[H],
      t: Text[T]
  ): Text[H :: T] =
    (h product t).contramap(l => (l.head, l.tail))

  // Generic
  implicit def generic[A, B](
      implicit
      gen: Generic.Aux[A, B],
      csv: Lazy[Text[B]]
  ): Text[A] =
    csv.value.contramap(gen.to)

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy