Skip to content

Commit

Permalink
Add mapOrKeepIn to F[Option[A]] syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
danicheg committed Jun 15, 2024
1 parent 050b138 commit 522e129
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/src/main/scala/mouse/foption.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ final class FOptionOps[F[_], A](private val foa: F[Option[A]]) extends AnyVal {
def mapIn[B](f: A => B)(implicit F: Functor[F]): F[Option[B]] =
F.map(foa)(_.map(f))

def mapOrKeepIn[B >: A](pf: PartialFunction[A, B])(implicit F: Functor[F]): F[Option[B]] =
F.map(foa)(_.map(a => pf.applyOrElse(a, identity[B])))

def asIn[B](b: => B)(implicit F: Functor[F]): F[Option[B]] =
mapIn(_ => b)

Expand Down

0 comments on commit 522e129

Please sign in to comment.