Opt
- Source
- __.scala
Def
Local
Inherited inherited
Stream
Stream
Returns single value stream or empty stream, if option is void
- Inherited from
- _extension
- Source
- _extension.scala
Value filter and converter
Value filter and converter
Discards value if given partial function is not defined
Otherwise value is converted to the function result
val o: Opt[String] = "foo"
o.collect { case v if v.startsWith("a") => "bar" } tp // Prints: \/
o.collect { case v if v.startsWith("f") => "bar" } tp // Prints: Opt(bar)
Note: If this is empty, it is returned as is
Note: collect
is similar to map_?
, but is less efficient, because PartialFunction has to be evaluated twice
- Inherited from
- _extension
- Source
- _extension.scala
Check contains
Check contains
Returns 'true' if option contains given value
'false' - otherwise
val o : Opt[String] = "foo"
o.contains("foo").tp // Prints: true
o.contains("bar").tp // Prints: false
- Inherited from
- _extension
- Source
- _extension.scala
Default value
Default value
Does nothing if option already contains a value
For void option, returns a new option with given value
var o : Opt[String] = "foo"
o.default("bar").tp // Prints: Opt(foo)
o = \/
o.default("bar").tp // Prints: Opt(bar)
- Inherited from
- _extension
- Source
- _extension.scala
Reversed filter
Reversed filter
Discards value if it satisfies given predicate
val o : Opt[String] = "foo"
o.drop(_.length > 2).tp // Prints: Opt(\/)
o.drop(_.length > 3).tp // Prints: Opt(foo)
- Inherited from
- _extension
- Source
- _extension.scala
Reversed value filter
Reversed value filter
Discards value if it is equal to given value
val o : Opt[String] = "foo"
o.dropOnly("foo").tp // Prints: Opt(\/)
o.dropOnly("bar").tp // Prints: Opt(foo)
- Inherited from
- _extension
- Source
- _extension.scala
Reversed void filter
Reversed void filter
Discards value if it is void, so the option itself becomes void
val s : ~[String] = \/
var o : Opt[~[String]] = s
o.tp // Prints: Opt(~())
o = o.dropVoid
o.tp // Prints: Opt(\/)
- Inherited from
- _extension
- Source
- _extension.scala
Legacy filter
Legacy filter
Discards value if it does not pass given filter function
Note: take is usually used instead.
- Inherited from
- _extension
- Source
- _extension.scala
Process nonexistent value
Process nonexistent value
Executes given function if option is void
Returns option itself
- Inherited from
- _extension
- Source
- _extension.scala
Process option value
Process option value
Executes given function with option value
Does nothing if option is void
Returns option itself
- Inherited from
- _extension
- Source
- _extension.scala
Get value
Get value
Returns value or fails if option is void
Note: This method is not widely used except for debugging and examples. or is the main way to resolve value
- Inherited from
- _extension
- Source
- _extension.scala
Void check
Void check
Returns true
if value is void and false
otherwise
Note: This operation is implicitly available for all types. It is explicit here to indicate efficient implementation.
- Inherited from
- _extension
- Source
- _extension.scala
Convert value
Convert value
Creates new option with value converted by the given function
Void option allways yeilds void option
"Abc".?.map(_.length) // Prints: Int.Opt(3)
Note. Operation returns specialized options for primitive values
- Inherited from
- _extension
- Source
- _extension.scala
Optional map
Optional map
Creates new option with value converted by optional function.
Void option allways yeilds void option
"a".? .map_?(s => if(s.length > 2) s.toUpperCase else \/).tp // Prints Opt(\/)
"abc".?.map_?(s => if(s.length > 2) s.toUpperCase else \/).tp // Prints Opt(ABC)
"a".? .map_?(s => if(s.length > 2) s.length else Int.Opt.\/).tp // Prints Int.Opt(\/)
"abc".?.map_?(s => if(s.length > 2) s.length else Int.Opt.\/).tp // Prints Int.Opt(3)
Note: The void option type has to be given explicitly
"abc".?.map_?{
case s if s.length > 2 => s.toUpperCase
case _ => \/
}.tp
Note. In case matching the last default case must be given, so it becomes regular, not partial function, which is slower
- Inherited from
- _extension
- Source
- _extension.scala
Mix two option values
Mix two option values
If either option is void, the void option is returned
Otherwise, the given function is applied with both values, resulting in a valued option
val io: Int.Opt = 4
var so: Opt[String] = \/
so.mix(io, _ * _).tp // Prints Opt(\/)
so = "abc_"
so.mix(io, _ * _).tp // Prints Opt(abc_abc_abc_abc_)
- Inherited from
- _extension
- Source
- _extension.scala
Not void check
Not void check
Returns true
if value is not void and false
otherwise
Note: This operation is implicitly available for all types. It is explicit here to indicate efficient implementation.
- Inherited from
- _extension
- Source
- _extension.scala
Value or default
Value or default
Returns option value, or if option is void, given default value
var o : Opt[String] = "foo"
(o or "bar").tp // Prints foo
o = \/
(o or "bar").tp // Prints bar
- Inherited from
- _extension
- Source
- _extension.scala
Default option
Default option
Returns this option if it is not void or given option otherwise
var o : Opt[String] = "foo"
var o2 : Opt[String] = "bar"
(o or_? o2).tp // Prints Opt(foo)
o = \/
(o or_? o2).tp // Prints Opt(bar)
- Inherited from
- _extension
- Source
- _extension.scala
Process value or no value
Process value or no value
Executes given function with option value or second given function if option is void
Returns option itself
- Inherited from
- _extension
- Source
- _extension.scala
To specialized option
To specialized option
Converts this option to specialized on primitive type
The operation will not compile if convertin to reference type
var o : Opt[Int] = 12
var io : Int.Opt = o.ref
- Inherited from
- _extension
- Source
- _extension.scala
Filter
Filter
Discards value if it does not satisfy given predicate
val o : Opt[String] = "foo"
o.take(_.length < 2).tp // Prints: Opt(\/)
o.take(_.length > 2).tp // Prints: Opt(foo)
- Inherited from
- _extension
- Source
- _extension.scala
Value filter
Value filter
Discards value if it is not equal to given value
val o : Opt[String] = "foo"
o.takeOnly("foo").tp // Prints: Opt(foo)
o.takeOnly("bar").tp // Prints: Opt(\/)
- Inherited from
- _extension
- Source
- _extension.scala
Value filter and type converter
Value filter and type converter
Discards value if it does not belong to the given type
Note, the result is mapped to the given type
val o: Opt[Any] = "1"
println(o.takeType[String]) // Prints: Opt(1)
println(o.takeType[Int]) // Prints: \/
Note: If this is empty, it is returned as is
- Inherited from
- _extension
- Source
- _extension.scala
To Java Optional
To Java Optional
Converts this option to java.util.Optional
- Inherited from
- _extension
- Source
- _extension.scala
To Scala Option
To Scala Option
Converts this option to scala.Option
- Inherited from
- _extension
- Source
- _extension.scala