com.redhat.et.silex.util

OptionalArg

final class OptionalArg[A] extends AnyVal

Provides idiomatic optional parameter values on top of Option, but which can be passed in as raw values, instead of having to pass in Some(value)

import com.redhat.et.silex.util.OptionalArg

def possiblyFilter(data: Seq[Int], filterMax: OptionalArg[Int] = None) = {
  // Treat an OptionalArg like an Option, for idiomatic handling of unset vals as None
  if (filterMax.isEmpty) data else data.filter(_ <= filterMax.get)
}

val data = Seq(1, -1, 2)

// default filterMax is None
possiblyFilter(data) // returns data unfiltered

// provide argument as (-1), instead of having to specify Some(-1)
possiblyFilter(data, filterMax = -1) // returns Seq(-1)

// Support full Option methods and implicit conversion to Option
import OptionalArg.fullOptionSupport
def possiblyFilterUsingMap(data: Seq[Int], filterMax: OptionalArg[Int] = None) = {
  // use the 'map' method on an OptionalArg:
  filterMax.map(t => data.filter(_ <= t)).getOrElse(data)
}
A

The underlying value type.

Linear Supertypes
AnyVal, NotNull, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. OptionalArg
  2. AnyVal
  3. NotNull
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new OptionalArg(option: Option[A])

    option

    The raw Option value. May be implicitly constructed from raw value of type A

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  2. final def ##(): Int

    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. def get: A

    Get the value of the optional argument, assuming the argument is not empty.

    Get the value of the optional argument, assuming the argument is not empty.

    returns

    the value of the optional argument, or throw an exception if it is None

  6. def getClass(): Class[_ <: AnyVal]

    Definition Classes
    AnyVal → Any
  7. def getOrElse[A1 >: A](d: ⇒ A1): A1

    Get the value of the optional argument if it is defined, otherwise return the given default.

    Get the value of the optional argument if it is defined, otherwise return the given default.

    d

    A block evaluating to a default value, if the the optional value is not defined

    returns

    The value of the optional argument if one was defined, otherwise the value of d

  8. def isDefined: Boolean

    Determine if the optional argument is defined (contains Some(value))

    Determine if the optional argument is defined (contains Some(value))

    returns

    true if option contains Some(value), false otherwise

  9. def isEmpty: Boolean

    Determine if the optional argument is empty (contains None)

    Determine if the optional argument is empty (contains None)

    returns

    true if the option is None, false otherwise

  10. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  11. val option: Option[A]

    The raw Option value.

    The raw Option value. May be implicitly constructed from raw value of type A

  12. def toString(): String

    Definition Classes
    Any

Inherited from AnyVal

Inherited from NotNull

Inherited from Any

Ungrouped