final class _Class[+A] extends AnyVal with Any.Able.Void

Value Option

Opt is a container, which can hold a single value or be void

Opt is readily convertible to Boolean, where Opt with value is 'true' and void is 'false'

Ordering
  1. Alphabetic
Inherited
  1. Opt
  2. Any.Able.Void
  3. scala.AnyVal
  4. scala.Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Constant

  1. val real: Any
    Attributes
    protected[scalqa]
    Definition Classes
    _Class

Method

  1. def apply(f: (A) ⇒ Any, p: ⇒ Any = \/): Opt[A]

    Process option, both: value or no value

    Process option, both: value or no value

    Takes two functions, one to process value, another - no value

    12.Opt.apply(_ * 2 lp) // Prints: 24
    
    12.Opt(_ * 4 lp)       // Prints: 48
    Definition Classes
    _Class
  2. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  3. def contains(parameter: Any): Boolean

    Check contains

    Check contains

    Returns 'true' only if there is value and it is equal to the given parameter

    'false' - otherwise

    12.Opt.contains(12).lp            // Prints: true
    
    12.Opt.let(NONE).contains(12).lp  // Prints: false
    Definition Classes
    _Class
  4. def drop(f: (A) ⇒ Boolean): Opt[A]

    Reversed filter

    Reversed filter

    Discards value if it passes given filtering function

    "foo".Opt.drop(_.length > 2).lp  // Prints: Opt.Void
    
    "foo".Opt.drop(_.length > 3).lp  // Prints: Opt(foo)
    Definition Classes
    _Class
    Note

    Nothing is done if this is void

  5. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  6. def isValue: Boolean

    Check for value

    Check for value

    Returns true if this option holds value, 'false' - otherwise

    12.Opt.isValue.lp            // Prints: true
    
    12.Opt.let(NONE).isValue.lp  // Prints: false
    Definition Classes
    _Class
  7. def isVoid: Boolean

    Void check

    Void check

    Returns true if this instance is void

    Definition Classes
    _ClassVoid
  8. def let(f: (A) ⇒ Boolean): Opt[A]

    Main filter

    Main filter

    Discards value if it does not pass given filtering function

    "foo".Opt.let(_.length > 2).lp  // Prints: Opt(foo)
    
    "foo".Opt.let(_.length > 3).lp  // Prints: Opt.Void

    Note: Opt.Void stays Opt.Void without evaluation

    Definition Classes
    _Class
  9. def letLookup[B](f: PartialFunction[A, B]): Opt[B]

    Filter and converter

    Filter and converter

    Discards value if given partial function is not defined

    2.Opt.letLookup({case v if(v < 5) => v * 10}) .lp   // Prints: Opt(20)
    
    7.Opt.letLookup({case v if(v < 5) => v * 10}) .lp   // Prints: Opt.Void

    Note: Opt.Void stays Opt.Void without evaluation

    Definition Classes
    _Class
  10. def letMap[B](f: (A) ⇒ Opt[B]): Opt[B]

    Filter and converter

    Filter and converter

    Discards value if given function returns Opt.Void

    Otherwise value is converted to the function result

    "abc".Opt.letMap(v => if(v.startsWith("a")) \/ else v).lp  // Prints: Opt.Void
    
    "xyz".Opt.letMap(v => if(v.startsWith("x")) \/ else v).lp  // Prints: Opt(xyz)
    
    "Cbs".Opt.letMap({
        case s if(s.startsWith("A")) => \/
        case s => s
     }).lp                                                     // Prints: Opt(Cbs)

    Note: Opt.Void stays Opt.Void without evaluation

    Definition Classes
    _Class
  11. def letMix[B, C](that: Opt[B])(mix: (A, B) ⇒ C): Opt[C]

    Mix filter

    Mix filter

    If either Opt is void, Opt.Void is returned

    Otherwise, mixed value is returned

    val o5: Opt[Int] = 5
    val ov: Opt[Int] = \/
    
    
    o5.letMix(ov)(_ * _) lp // Prints: Opt.Void
    
    ov.letMix(o5)(_ * _) lp // Prints: Opt.Void
    
    o5.letMix(o5)(_ * _) lp // Prints: Opt(25)
    
    // same as
    
    {for(x <- o5; y <- o5) yeild x * y}.lp
    Definition Classes
    _Class
  12. def letType[B](implicit t: ClassTag[B]): Opt[B]

    Filter and type converter

    Filter and type converter

    Discards value if it does not belong to the given type

    Note, the result is mapped to the given type

    def o: Opt[Any] = "1"
    
    o.letAs[String].lp // Prints: Opt(1)
    
    o.letAs[Int].lp    // Prints: Opt.Void

    Note: Opt.Void stays Opt.Void without evaluation

    Definition Classes
    _Class
  13. def map[B](f: (A) ⇒ B): Opt[B]

    Convert value

    Convert value

    Creates new option with value converted by the given function

    If there is no value, this is returned as is

    2.Opt.map(_ * 10) lp   // Prints: Opt(20)
    Definition Classes
    _Class
  14. def orElse[B >: A](default: ⇒ B): B

    Value or default

    Value or default

    Returns value, or if none, then given default

    Note. Opt.or is strictly typed equivalent, which should be used in most cases

    "abc".Opt or "xyz".lp  // Prints: abc
    
    Opt.Void  or "xyz".lp  // Prints: xyz
    Definition Classes
    _Class
  15. def orElseOpt[B >: A](that: ⇒ Opt[B]): Opt[B]

    Default option

    Default option

    Returns this Opt, or if it is void, then given default

    Note. Opt.orOpt is strictly typed equivalent, which should be used in most cases

    "abc".Opt orOpt "xyz".Opt lp;  // Prints: Opt(abc)
    
    Opt.Void  orOpt "xyz".Opt lp;  // Prints: Opt(xyz)
    Definition Classes
    _Class
  16. def swap[B](newValue: ⇒ B): Opt[B]

    Replace value

    Replace value

    Creates new option with value replaced with newValue

    Opt.Void stays Opt.Void

    "foo".Opt.swap("bar") lp // Prints: Opt(bar)
    
    Opt.Void.swap("bar")  lp // Prints: Opt.Void
    Definition Classes
    _Class
  17. def toOut(d: ⇒ Deficiency = "Value is not available"): Util.Out[A]

    Convert to outcome

    Convert to outcome

    Convert this Opt to outcome, optionally providing custom Deficiency for void case

    Definition Classes
    _Class
  18. def toString(): String

    Convert to String

    Convert to String

    Returns "Opt.Void" or "Opt(" + value + ")" String

    Definition Classes
    _Class → Any
  19. def value: A

    Value

    Value

    Returns value, or if void - fails

    12.Opt.value.lp            // Prints: 12
    
    12.Opt.let(NONE).value.lp  // Fails on execution
    Definition Classes
    _Class

Operator

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): scala.Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
Linear Supertypes
Any.Able.Void, AnyVal, Any
Source: _Class.scala