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

org.specs2.fp.Identityx.scala Maven / Gradle / Ivy

There is a newer version: 5.5.8
Show newest version
package org.specs2
package fp

trait Identityx:
  /** These extension methods provide the possibility to execute a function on an object if a condition is true If not,
    * the object is returned
    */
  extension [T](t: =>T)
    def orWhen(condition: Boolean)(f: T => T): T =
      if condition then f(t) else t

  extension [S <: T, T: Monoid](t: =>S)
    def orEmptyUnless(condition: Boolean): T =
      t `orEmptyWhen` !condition

    def orEmptyWhen(condition: Boolean): T =
      if condition then summon[Monoid[T]].zero else t

object Identityx extends Identityx




© 2015 - 2024 Weber Informatics LLC | Privacy Policy