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

org.virtuslab.ideprobe.protocol.Setting.scala Maven / Gradle / Ivy

There is a newer version: 0.53.0
Show newest version
package org.virtuslab.ideprobe.protocol

sealed trait Setting[+A] {
  def map[B](f: A => B): Setting[B]
  def foreach(f: A => Unit): Unit = map[Unit](f)
}

object Setting {
  case class Changed[A](value: A) extends Setting[A] {
    override def map[B](f: A => B): Setting[B] = Setting.Changed(f(value))
  }
  object Unchanged extends Setting[Nothing] {
    override def map[B](f: Nothing => B): Setting[B] = this
  }

  implicit class OptionalSetting[A](val s: Setting[Option[A]]) extends AnyVal {
    def flatten: Setting[A] = s match {
      case Unchanged            => Unchanged
      case Changed(Some(value)) => Changed(value)
      case Changed(None)        => Unchanged
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy