io.hireproof.structure.package.scala Maven / Gradle / Ivy
The newest version!
package io.hireproof
import cats.data.Chain
import cats.syntax.all._
package object structure {
type |*|[+A, +B] = (A, B)
object |*| {
def unapply[A, B](value: A |*| B): Some[A |*| B] = Some(value)
}
type |+|[+A, +B] = Either[A, B]
object |+| {
def unapply[A, B](value: A |+| B): Some[A |+| B] = Some(value)
}
private[structure] def collectAndRemoveFirst[A, B](
chain: Chain[A]
)(pf: PartialFunction[A, B]): (Chain[A], Option[B]) = {
var result: Option[B] = none
val filtered = chain.filter { a =>
if (result.isEmpty && pf.isDefinedAt(a)) {
result = pf.apply(a).some
false
} else true
}
(filtered, result)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy