All Downloads are FREE. Search and download functionalities are using the official Maven repository.

harness.cli.Defaultable.scala Maven / Gradle / Ivy

There is a newer version: 5.1.3
Show newest version
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