Class/Object

io.radanalytics.silex.util

OptionalArg

Related Docs: object OptionalArg | package util

Permalink

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 io.radanalytics.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, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OptionalArg
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

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

    Permalink

    option

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

Value Members

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

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

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

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

    Permalink
    Definition Classes
    Any
  5. def get: A

    Permalink

    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]

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

    Permalink

    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

    Permalink

    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

    Permalink

    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

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

    Permalink

    The raw Option value.

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

  12. def toString(): String

    Permalink
    Definition Classes
    Any

Inherited from AnyVal

Inherited from Any

Ungrouped