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

ceylon.language.emptyOrSingleton.ceylon Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
"A singleton [[Tuple]] with the given [[element]] if the 
 given element is non-null, or the [[empty sequence|Empty]] 
 otherwise. This operation transforms an optional type `T?`
 to a sequence type `[]|[T]` allowing optional values to be
 the subject of operations defined for [[streams|Iterable]].
 
 For example, [[flat mapping|Iterable.flatMap]] 
 `emptyOrSingleton()` reproduces the behavior of 
 [[Iterable.coalesced]]. The expression
 
     { \"1.23\", \"foo\", \"5.67\", \"-1\", \"\" }
             .map(parseFloat)
             .flatMap(emptyOrSingleton)
 
 produces the stream:
  
     { 1.23, 5.67, -1.0 }"
see (`class Tuple`, `interface Empty`)
tagged("Sequences")
shared []|[Element&Object] emptyOrSingleton
        (Element element)
        => if (exists element) then [element] else [];




© 2015 - 2024 Weber Informatics LLC | Privacy Policy