harness.cli.Defaultable.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harness-cli_3 Show documentation
Show all versions of harness-cli_3 Show documentation
Miscellaneous libraries/utilities for Scala.
package harness.cli
import cats.syntax.option.*
object Defaultable {
sealed trait Optional[+V] {
final def map[V2](f: V => V2): Optional[V2] =
this match {
case Defaultable.Some(value) => Defaultable.Some(f(value))
case Defaultable.Auto => Defaultable.Auto
case Defaultable.None => Defaultable.None
}
// TODO (KR) : remove?
final def toOption: Option[V] = this match
case Some(value) => scala.Some(value)
case Auto => scala.None
case None => scala.None
}
sealed trait NonOptional[+V] extends Optional[V]
case object Auto extends NonOptional[Nothing]
final case class Some[+V](value: V) extends NonOptional[V]
case object None extends Optional[Nothing]
}
given [A]: Conversion[A, Defaultable.NonOptional[A]] = Defaultable.Some(_)
given [A]: Conversion[Option[A], Defaultable.Optional[A]] = {
case Some(value) => Defaultable.Some(value)
case None => Defaultable.None
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy