Skip to content

Instantly share code, notes, and snippets.

@nefilim
Last active May 24, 2022 18:15
Show Gist options
  • Save nefilim/44f48974ca4b9b423aea1e46f68afbb3 to your computer and use it in GitHub Desktop.
Save nefilim/44f48974ca4b9b423aea1e46f68afbb3 to your computer and use it in GitHub Desktop.
object SuppliedSemigroup {
import cats.kernel.Semigroup
implicit val maxDurationSemigroup: Semigroup[Duration] = Semigroup((a, b) => if (a > b) a else b)
// implicit val optionMonoid: Monoid[Option[Duration]] = cats.kernel.instances.option.catsKernelStdMonoidForOption(maxDurationSemigroup)
def optionDurationCombineSemigroup(rp1: Option[Duration], rp2: Option[Duration])(implicit mo: Semigroup[Option[Duration]]): Option[Duration] = {
mo.combine(rp1, rp2)
}
def main(args: Array[String]): Unit = {
println(optionDurationCombineSemigroup(Some(2.minute), Some(90.seconds)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment