harness.core.StringCodec.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harness-core_sjs1_3 Show documentation
Show all versions of harness-core_sjs1_3 Show documentation
Miscellaneous libraries/utilities for Scala.
The newest version!
package harness.core
import cats.data.NonEmptyList
import cats.syntax.either.*
final case class StringCodec[A](
encoder: StringEncoder[A],
decoder: StringDecoder[A],
) {
def iemap[B](to: A => Either[String, B], from: B => A): StringCodec[B] =
StringCodec(encoder.imap(from), decoder.flatMap(to(_).leftMap(NonEmptyList.one)))
}
object StringCodec {
implicit def fromParts[A](implicit encoder: StringEncoder[A], decoder: StringDecoder[A]): StringCodec[A] =
StringCodec[A](encoder, decoder)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy