Skip to content

Commit

Permalink
Optimize mapAccumulateFilter for Option
Browse files Browse the repository at this point in the history
  • Loading branch information
Masynchin committed Feb 19, 2024
1 parent cb6d411 commit 277593b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/scala/cats/instances/option.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ private[instances] trait OptionInstancesBinCompat0 {
case None => G.pure(Option.empty[A])
case Some(a) => G.map(f(a))(b => if (b) Some(a) else None)
}

override def mapAccumulateFilter[S, A, B](init: S, fa: Option[A])(f: (S, A) => (S, Option[B])): (S, Option[B]) = {
fa match {
case Some(a) => f(init, a)
case None => (init, None)
}
}

}
}

0 comments on commit 277593b

Please sign in to comment.