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

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

There is a newer version: 3.7
Show newest version
package org.specs2
package control

import scalaz.Monoid

/**
 * This class provides the possibility to execute a function on an object if a condition is true
 * If not, the object is returned
 */
private[specs2]
class Identityx[T](t: =>T) {
  def ?>(f: T => T)(implicit condition: Boolean = true) = when(condition)(f)
  def when(condition: Boolean)(f: T => T) = if (condition) f(t) else t
  def unless(condition: Boolean)(implicit m: Monoid[T]) = if (condition) t else m.zero
}

private[specs2]
object Identityx {
  implicit def identityx[T](f: =>T): Identityx[T] = new Identityx(f)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy