Skip to content

Commit

Permalink
Add Mapping.imap
Browse files Browse the repository at this point in the history
  • Loading branch information
taig committed Nov 20, 2024
1 parent 0dd86b7 commit 7b3f5c2
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ import cats.syntax.all.*
import scala.annotation.targetName

sealed abstract class Mapping[A, B] extends Inject[A, B]:
self =>

def values: NonEmptyList[A]

final def imap[T](f: A => T)(g: T => A): Mapping[T, B] = new Mapping[T, B]:
override def values: NonEmptyList[T] = self.values.map(f)
override def inj: T => B = g.andThen(self.inj)
override def prj: B => Option[T] = self.prj(_).map(f)

final def product[C](mapping: Mapping[C, B])(
merge: (B, B) => B,
split: B => Option[(B, B)]
Expand Down

0 comments on commit 7b3f5c2

Please sign in to comment.