Package kotlin.nullable

Functions for treating nullable types as composable collections of zero or one element

See:
          Description

Function Summary
fun <T>
T?
all(predicate: (T) -> Boolean): Boolean
Returns true if the element is not null and matches the given predicate
fun <T>
T?
any(predicate: (T) -> Boolean): Boolean
Returns true if the element is not null and matches the given predicate
fun <T>
T?
count(predicate: (T) -> Boolean): Int
Returns the 1 if the element is not null else 0
fun <T>
T?
filter(predicate: (T) -> Boolean): T?
Returns a new List containing all elements in this collection which match the given predicate
fun <T>
T?
filterNot(predicate: (T) -> Boolean): Collection<T>
Returns a new collection containing all elements in this collection which do not match the given predicate
fun <T>
T?
filterNotNull(): Collection<T>
Returns a List containing all the non null elements in this collection
fun <T, C>
T?
filterNotNullTo(result: C): C
Filters all the null elements in this collection winto the given result collection
fun <T, C>
T?
filterNotTo(result: C, predicate: (T) -> Boolean): C
Returns a new collection containing all elements in this collection which do not match the given predicate
fun <T, C>
T?
filterTo(result: C, predicate: (T) -> Boolean): C
Filters all elements in this collection which match the given predicate into the given result collection
fun <T>
T?
find(predicate: (T) -> Boolean): T?
Returns the first item which matches the predicate if this element is not null else null
fun <T, R>
T?
flatMap(transform: (T) -> MutableCollection<R>): Collection<R>
Returns the result of transforming each item in the collection to a one or more values which
are concatenated together into a single collection
fun <T, R>
T?
flatMapTo(result: MutableCollection<R>, transform: (T) -> MutableCollection<R>): Collection<R>
Returns the result of transforming each item in the collection to a one or more values which
are concatenated together into a single collection
fun <T>
T?
fold(initial: T, operation: (T, T) -> T): T
Folds all the values from from left to right with the initial value to perform the operation on sequential pairs of values
fun <T>
T?
foldRight(initial: T, operation: (T, T) -> T): T
Folds all the values from right to left with the initial value to perform the operation on sequential pairs of values
fun <T>
T?
forEach(operation: (T) -> Unit): Unit
Performs the given operation on each element inside the collection
fun <T, K>
T?
groupBy( [result: MutableMap<K, MutableList<T>>], toKey: (T) -> K): Map<K, MutableList<T>>
Iterates through the collection performing the transformation on each element and using the result
as the key in a map to group elements by the result
fun <T>
T?
makeString( [separator: String, prefix: String, postfix: String]): String
Creates a String from the nullable or item with the given prefix and postfix if supplied
fun <T, R>
T?
map(transform: (T) -> R): R?
Returns the nullable result of transforming this with the given transformation function
fun <T, R, C>
T?
mapTo(result: C, transform: (T) -> R): C
Transforms each element of this collection with the given function then adds the results to the given collection
fun <T>
T?
reverse(): T?
Returns itself since it can’t be reversed as it can contain at most one item
fun <T, C>
T?
toCollection(result: C): C
Copies the collection into the given collection
fun <T>
T?
toLinkedList(): LinkedList<T>
Converts the collection into a LinkedList
fun <T>
T?
toList(): List<T>
Converts the collection into a List
fun <T>
T?
toSet(): Set<T>
Converts the collection into a Set
fun <T>
T?
toSortedSet(): SortedSet<T>
Converts the collection into a SortedSet
 

Extensions Summary
jet.Any hashCodeOrDefault
 

Package kotlin.nullable Description

Contents

Function Detail
source

all


 fun <T> T?.all(predicate: (T) -> Boolean): Boolean

Returns true if the element is not null and matches the given predicate

source

any


 fun <T> T?.any(predicate: (T) -> Boolean): Boolean

Returns true if the element is not null and matches the given predicate

source

count


 fun <T> T?.count(predicate: (T) -> Boolean): Int

Returns the 1 if the element is not null else 0

source

filter


 fun <T> T?.filter(predicate: (T) -> Boolean): T?

Returns a new List containing all elements in this collection which match the given predicate

source

filterNot


 fun <T> T?.filterNot(predicate: (T) -> Boolean): Collection<T>

Returns a new collection containing all elements in this collection which do not match the given predicate

source

filterNotNull


 fun <T> T?.filterNotNull(): Collection<T>

Returns a List containing all the non null elements in this collection

source

filterNotNullTo


 fun <T, C> T?.filterNotNullTo(result: C): C

Filters all the null elements in this collection winto the given result collection

source

filterNotTo


 fun <T, C> T?.filterNotTo(result: C, predicate: (T) -> Boolean): C

Returns a new collection containing all elements in this collection which do not match the given predicate

source

filterTo


 fun <T, C> T?.filterTo(result: C, predicate: (T) -> Boolean): C

Filters all elements in this collection which match the given predicate into the given result collection

source

find


 fun <T> T?.find(predicate: (T) -> Boolean): T?

Returns the first item which matches the predicate if this element is not null else null

source

flatMap


 fun <T, R> T?.flatMap(transform: (T) -> MutableCollection<R>): Collection<R>

Returns the result of transforming each item in the collection to a one or more values which
are concatenated together into a single collection

source

flatMapTo


 fun <T, R> T?.flatMapTo(result: MutableCollection<R>, transform: (T) -> MutableCollection<R>): Collection<R>

Returns the result of transforming each item in the collection to a one or more values which
are concatenated together into a single collection

source

fold


 fun <T> T?.fold(initial: T, operation: (T, T) -> T): T

Folds all the values from from left to right with the initial value to perform the operation on sequential pairs of values

For example to sum together all numeric values in a collection of numbers it would be
{code}val total = numbers.fold(0){(a, b) -> a + b}{code}

source

foldRight


 fun <T> T?.foldRight(initial: T, operation: (T, T) -> T): T

Folds all the values from right to left with the initial value to perform the operation on sequential pairs of values

source

forEach


 fun <T> T?.forEach(operation: (T) -> Unit): Unit

Performs the given operation on each element inside the collection

source

groupBy


 fun <T, K> T?.groupBy( [result: MutableMap<K, MutableList<T>>], toKey: (T) -> K): Map<K, MutableList<T>>

Iterates through the collection performing the transformation on each element and using the result
as the key in a map to group elements by the result

source

makeString


 fun <T> T?.makeString( [separator: String, prefix: String, postfix: String]): String

Creates a String from the nullable or item with the given prefix and postfix if supplied

source

map


 fun <T, R> T?.map(transform: (T) -> R): R?

Returns the nullable result of transforming this with the given transformation function

source

mapTo


 fun <T, R, C> T?.mapTo(result: C, transform: (T) -> R): C

Transforms each element of this collection with the given function then adds the results to the given collection

source

reverse


 fun <T> T?.reverse(): T?

Returns itself since it can’t be reversed as it can contain at most one item

source

toCollection


 fun <T, C> T?.toCollection(result: C): C

Copies the collection into the given collection

source

toLinkedList


 fun <T> T?.toLinkedList(): LinkedList<T>

Converts the collection into a LinkedList

source

toList


 fun <T> T?.toList(): List<T>

Converts the collection into a List

source

toSet


 fun <T> T?.toSet(): Set<T>

Converts the collection into a Set

source

toSortedSet


 fun <T> T?.toSortedSet(): SortedSet<T>

Converts the collection into a SortedSet



Copyright © 2010-2012. All Rights Reserved.