package io.rtron.std

Classes

Name Description
data class ContextMessage<V> : Any

A class for adding context messages to an object of type V.

enum class MovingWindowShape: Enum<MovingWindowShape>

Shape of a moving window operation to be returned.

data class Optional<T> : Any

A container object which optionally contains a value of type T.

open class Property<T> : Any

Read-only property of type T with context information, whether the property contains a default value. Usable as property delegate.

class SettableProperty<T> : Property<T>

Mutable property usable as property delegate.

Subpackages

Name Description
package io.rtron.std.date

Methods

windowedEnclosing

fun <T> Sequence<T>.windowedEnclosing(size: Int, step: Int): Sequence><List<T>>

Creates a sequence of lists with size, iterating through the (receiver) sequence.

Receiver

Name Description
Sequence<T>

the base sequence used to generate the sublists of size

Parameters

Name Description
size: Int

the size of the sublists to be returned

step: Int

the number of elements to move on

ReturnValue

Name Description
Sequence><List<T>>

the sequence of sublists

handleMessage

inline fun <V : Any> ContextMessage<V>.handleMessage(block: (List<String>)->Unit): V

Handle a message with block and then return only the ContextMessage.value.

Receiver

Name Description
ContextMessage<V>

ContextMessage to be handled

Parameters

Name Description
block: (List<String>)->Unit

the actual handler for the context message

ReturnValue

Name Description
V

only the remaining ContextMessage.value

map

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

Receiver

Name Description
Optional<T>

Parameters

Name Description
transform: (T)->R

ReturnValue

Name Description
Optional<R>

getOrElse

fun <T> Optional<T>.getOrElse(defaultValue: T): T

Receiver

Name Description
Optional<T>

Parameters

Name Description
defaultValue: T

ReturnValue

Name Description
T

handleSuccess

inline fun <V, E : Exception> Result<V, E>.handleSuccess(block: (Result.Success<V>)->Nothing): E

Handle the Result.Success with block and return the Result.Failure.

Receiver

Name Description
Result<V, E>

the Result to be handled

Parameters

Name Description
block: (Result.Success<V>)->Nothing

the actual handler of the Result.Success

ReturnValue

Name Description
E

remaining Result.Failure

handleFailure

inline fun <V, E : Exception> Result<V, E>.handleFailure(block: (Result.Failure<E>)->Nothing): V

Handle the Result.Failure with block and return the Result.Success.

Receiver

Name Description
Result<V, E>

the Result to be handled

Parameters

Name Description
block: (Result.Failure<E>)->Nothing

the actual handler of the Result.Failure

ReturnValue

Name Description
V

remaining Result.Success

distinctConsecutive

inline fun <T, K> Iterable<T>.distinctConsecutive(crossinline selector: (T)->K): List<T>

Returns a list without consecutive elements which have the same return by the given selector function.

Receiver

Name Description
Iterable<T>

the base list for which the consecutive duplicates according to the selector are being removed

Parameters

Name Description
crossinline selector: (T)->K

if the resulting elements of the selector is equal, the duplicates are being removed

ReturnValue

Name Description
List<T>

list without consecutive duplicates

distinctConsecutiveEnclosing

inline fun <T, K> Iterable<T>.distinctConsecutiveEnclosing(crossinline selector: (T)->K): List<T>

Returns a list without consecutive elements which have the same return by the given selector function. The operation is performed enclosing around the list, meaning that the selector(lastElement) == selector(firstElement) is also evaluated.

Receiver

Name Description
Iterable<T>

the base list for which the consecutive duplicates according to the selector are being removed

Parameters

Name Description
crossinline selector: (T)->K

if the resulting elements of the selector is equal, the duplicates are being removed

ReturnValue

Name Description
List<T>

list without consecutive duplicates (also potentially enclosing duplicates)

filterToStrictSortingBy

inline fun <T, K : Comparable<K>> Iterable<T>.filterToStrictSortingBy(crossinline selector: (T)->K): List<T>

Returns a list sorted according to natural sort order of the value returned by specified selector function by filtering all unsorted elements.

Receiver

Name Description
Iterable<T>

Parameters

Name Description
crossinline selector: (T)->K

ReturnValue

Name Description
List<T>

filterToStrictSortingByDescending

inline fun <T, K : Comparable<K>> Iterable<T>.filterToStrictSortingByDescending(crossinline selector: (T)->K): List<T>

Returns a list sorted descending according to natural sort order of the value returned by specified selector function by filtering all unsorted elements.

Receiver

Name Description
Iterable<T>

Parameters

Name Description
crossinline selector: (T)->K

ReturnValue

Name Description
List<T>

filterToSorting

inline fun <T> Iterable<T>.filterToSorting(predicate: (T, T)->Boolean): List<T>

Returns a sorted list according to the predicate by filtering all unsorted elements.

Example: Strict ordering Given a list: 1, 3, 2, 4 Predicate: first < second Returning list: 1, 3, 4 (2 was dropped, since 3 < 2 is false)

Receiver

Name Description
Iterable<T>

iterable to be filtered

Parameters

Name Description
predicate: (T, T)->Boolean

comparison function

ReturnValue

Name Description
List<T>

filtered list without the unsorted elements

cumulativeSum

fun Iterable<Double>.cumulativeSum(): List<Double>

Returns the cumulative sum.

Receiver

Name Description
Iterable<Double>

list of individual Double values on which the cumulative sum operation is performed on

ReturnValue

Name Description
List<Double>

list of accumulated values

cumulativeSum

fun Iterable<Float>.cumulativeSum(): List<Float>

Returns the cumulative sum.

Receiver

Name Description
Iterable<Float>

list of individual Float values on which the cumulative sum operation is performed on

ReturnValue

Name Description
List<Float>

list of accumulated values

cumulativeSum

fun Iterable<Int>.cumulativeSum(): List<Int>

Returns the cumulative sum.

Receiver

Name Description
Iterable<Int>

list of individual Int values on which the cumulative sum operation is performed on

ReturnValue

Name Description
List<Int>

list of accumulated values

zip

fun <T, R, S> Iterable<T>.zip(otherA: Iterable<R>, otherB: Iterable<S>): List<Triple<T, R, S>>

Returns a list of triples built from the elements of this collection and the otherA as well as otherB array with the same index. The returned list has length of the shortest collection.

Receiver

Name Description
Iterable<T>

Parameters

Name Description
otherA: Iterable<R>

array to be combined

otherB: Iterable<S>

array to be combined

ReturnValue

Name Description
List<Triple<T, R, S>>

list of Triple having the length of the shortest collection

zip

fun <T, R, S, V> Iterable<T>.zip(otherA: Iterable<R>, otherB: Iterable<S>, transform: (T, R, S)->V): List<V>

Returns a list of values built from this collection and the otherA as well as otherB array with the same index. For combining the arrays the transform function is applied.

Receiver

Name Description
Iterable<T>

Parameters

Name Description
otherA: Iterable<R>

array to be combined

otherB: Iterable<S>

array to be combined

transform: (T, R, S)->V

ReturnValue

Name Description
List<V>

list having the length of the shortest collection

zipWithNextToTriples

fun <T> Iterable<T>.zipWithNextToTriples(): List<Triple<T, T, T>>

Zip each element in this list with the next two elements and zip them to a Triple.

Receiver

Name Description
Iterable<T>

ReturnValue

Name Description
List<Triple<T, T, T>>

list of triples

isSortedBy

inline fun <T, R : Comparable<R>> Iterable<T>.isSortedBy(crossinline selector: (T)->R): Boolean

Returns true, if the list is sorted ascending according to the selector.

Receiver

Name Description
Iterable<T>

Parameters

Name Description
crossinline selector: (T)->R

the return of the selector is used for evaluating whether the list is sorted

ReturnValue

Name Description
Boolean

true, if the list is sorted in ascending order

isSorted

fun <T : Comparable<T>> Iterable<T>.isSorted(): Boolean

Returns true, if list is sorted in weak ascending order.

Receiver

Name Description
Iterable<T>

list to be evaluated

ReturnValue

Name Description
Boolean

true, if the list is sorted in weak ascending order

isStrictlySorted

fun <T : Comparable<T>> Iterable<T>.isStrictlySorted(): Boolean

Returns true, if list is sorted in strict ascending order.

Receiver

Name Description
Iterable<T>

list to be evaluated

ReturnValue

Name Description
Boolean

true, if the list is sorted in strict ascending order

isSortedDescending

fun <T : Comparable<T>> Iterable<T>.isSortedDescending(): Boolean

Returns true, if list is sorted in weak descending order.

Receiver

Name Description
Iterable<T>

list to be evaluated

ReturnValue

Name Description
Boolean

true, if the list is sorted in weak descending order

isStrictlySortedDescending

fun <T : Comparable<T>> Iterable<T>.isStrictlySortedDescending(): Boolean

Returns true, if list is sorted in strict descending order.

Receiver

Name Description
Iterable<T>

list to be evaluated

ReturnValue

Name Description
Boolean

true, if the list is sorted in strict descending order

handleFailure

inline fun <V, E : Exception> Iterable<Result<V, E>>.handleFailure(block: (Result.Failure<E>)->Nothing): List<V>

A failure within the list is handled with the block operation, otherwise the value list of Result.Success is returned.

Receiver

Name Description
Iterable<Result<V, E>>

the list of Result to be handled

Parameters

Name Description
block: (Result.Failure<E>)->Nothing

the handler in case of an Result.Failure

ReturnValue

Name Description
List<V>

the list of values of the Result.Success

handleAndRemoveFailure

inline fun <V, E : Exception> Iterable<Result<V, E>>.handleAndRemoveFailure(block: (Result.Failure<E>)->Unit): List<V>

Handle all Result.Failure with block and return only the values of Result.Success.

Receiver

Name Description
Iterable<Result<V, E>>

the list of Result to be handled

Parameters

Name Description
block: (Result.Failure<E>)->Unit

the handler in case of an Result.Failure

ReturnValue

Name Description
List<V>

the list of values of the Result.Success

handleAndRemoveFailureIndexed

inline fun <V, E : Exception> Iterable<Result<V, E>>.handleAndRemoveFailureIndexed(block: (Int, Result.Failure<E>)->Unit): List<V>

Handle all Result.Failure with block containing the index and exception and return only the values of Result.Success.

Receiver

Name Description
Iterable<Result<V, E>>

the list of Result to be handled

Parameters

Name Description
block: (Int, Result.Failure<E>)->Unit

the handler in case of an Result.Failure with index information

ReturnValue

Name Description
List<V>

the list of values of the Result.Success

ignoreFailure

fun <V, E : Exception> Iterable<Result<V, E>>.ignoreFailure(): List<V>

Ignore and filter out all Result.Failure.

Receiver

Name Description
Iterable<Result<V, E>>

the list of Result to be handled

ReturnValue

Name Description
List<V>

the list of values of the Result.Success

zipWithNextEnclosing

fun <T> Iterable<T>.zipWithNextEnclosing(): List<Pair<T, T>>

Returns a list of pairs for each two adjacent elements in this collection including a pair of the last and first element.

Receiver

Name Description
Iterable<T>

iterable containing all elements which are zipped

ReturnValue

Name Description
List<Pair<T, T>>

list of all pairs of two adjacent elements (with last and first element pair), whereby the returned list is empty if the receiver contains less than two elements

zipWithConsecutives

fun <T, K> Iterable<T>.zipWithConsecutives(keySelector: (T)->K): List<List<T>>

Zips consecutive elements of the original list by the key returned by the given keySelector function applied to each element and returns a list where each containing list holds the selected elements.

Receiver

Name Description
Iterable<T>

contains the elements which are zipped

Parameters

Name Description
keySelector: (T)->K

if keySelector of consecutive elements return equal objects, zipping is performed

ReturnValue

Name Description
List<List<T>>

list of all zipped elements (also represented as list), whereas the returned nested lists preserve the iteration order

zipWithConsecutivesEnclosing

fun <T, K> Iterable<T>.zipWithConsecutivesEnclosing(keySelector: (T)->K): List<List<T>>

Zips consecutive elements of the original list by the key returned by the given keySelector function applied to each element and returns a list where each containing list holds the selected elements. If last zip and first zip have the same key, the last zip is prepended.

Receiver

Name Description
Iterable<T>

contains the elements which are zipped

Parameters

Name Description
keySelector: (T)->K

if keySelector of consecutive elements return equal objects, zipping is performed

ReturnValue

Name Description
List<List<T>>

list of all zipped elements (also represented as list), whereas the returned nested lists preserve the iteration order

hasSameSizeAs

fun <T, K> Collection<T>.hasSameSizeAs(vararg others: Collection<K>):

Returns true, if all lists have the same number of elements.

Receiver

Name Description
Collection<T>

first list used for comparing the sizes of the lists

Parameters

Name Description
vararg others: Collection<K>

other lists used for the size comparison

ReturnValue

Name Description

true, if all lists have the same size

handleMessage

inline fun <V : Any> List<ContextMessage<V>>.handleMessage(block: (ContextMessage<V>)->Unit): List<V>

Handles a list of messages with block and then returns only the list of ContextMessage.value.

Receiver

Name Description
List<ContextMessage<V>>

list of ContextMessage to be handled

Parameters

Name Description
block: (ContextMessage<V>)->Unit

the actual handler for the context message

ReturnValue

Name Description
List<V>

remaining list of ContextMessage.value

moveWindow

fun <S, T, K> List<S>.moveWindow(window: List<T>, multiplication: (S, T)->K, addition: (K, K)->K, shape: MovingWindowShape): List<K>

Returns a list, over which window was moved/ slided over. This function is an abstract implementation of the moving average, but it can also be used to realize boolean window filters.

Receiver

Name Description
List<S>

the list over which the window is moved

Parameters

Name Description
window: List<T>

the window is moved or slided over the receiver

multiplication: (S, T)->K

higher order function for multiplying the elements of the receiver list with elements of the window

addition: (K, K)->K

higher order function for addition the results to reduce them to the list with elements of type K

shape: MovingWindowShape

the resulting list is as long as the base list if MovingWindowShape.SAME or base.size + other.size, if MovingWindowShape.FULL

ReturnValue

Name Description
List<K>

the size of the resulting list depends on the shape

moveWindow

fun List<Boolean>.moveWindow(window: List<Boolean>, shape: MovingWindowShape): List<Boolean>

Moving a window over a Boolean list with boolean window.

Receiver

Name Description
List<Boolean>

the list over which the window is moved

Parameters

Name Description
window: List<Boolean>

the window is moved or slided over the receiver

shape: MovingWindowShape

the resulting list is as long as the base list if MovingWindowShape.SAME or base.size + other.size, if MovingWindowShape.FULL

ReturnValue

Name Description
List<Boolean>

an element of the returned list is true, if the multiplication of at least one element of the receiver and window list is true

filterWindowed

fun <T> List<T>.filterWindowed(dropIndices: List<Boolean>, predicate: (List<T>)->Boolean): List<T>

Returns a list containing all elements not matching the given predicate. The predicate is operated on a sublist and if the pattern matches the elements with indices dropIndices are dropped.

Example Given a list: A, A, B, C, A, A, B, C, A Predicate: it0 == A && it1 == B && it2 == C DropIndices: (false, true, true) Return: A, B, A, B

Receiver

Name Description
List<T>

list on which the window filter is applied

Parameters

Name Description
dropIndices: List<Boolean>

the list of Boolean indicating the the indices that are dropped in the case of a matching predicate

predicate: (List<T>)->Boolean

if the predicate returns true, the indices are dropped according to the dropIndices

ReturnValue

Name Description
List<T>

list without elements which match the predicate

filterWindowedEnclosing

fun <T> List<T>.filterWindowedEnclosing(windowSize: Int, predicate: (List<T>)->Boolean): List<T>

Filters out all elements, when the predicate with windowSize is matching.

Receiver

Name Description
List<T>

list on which the window filter is applied

Parameters

Name Description
windowSize: Int

size of the window

predicate: (List<T>)->Boolean

if the predicate returns true, all elements are filtered out

ReturnValue

Name Description
List<T>

list without elements which match the predicate

filterWindowedEnclosing

fun <T> List<T>.filterWindowedEnclosing(dropIndices: List<Boolean>, predicate: (List<T>)->Boolean): List<T>

Filter windows that follow which match the predicate. The filter window is executed enclosing the list.

Example Given a list: A, A, B, C, A Predicate: it0 == it1 DropIndices: (true, false) -> A, B, C (edge pattern also dropped) DropIndices: (false, true) -> A, B, C, A (edge pattern not dropped)

Receiver

Name Description
List<T>

list on which the window filter is applied

Parameters

Name Description
dropIndices: List<Boolean>

the list of Boolean indicating the the indices that are dropped in the case of a matching predicate

predicate: (List<T>)->Boolean

if the predicate returns true, the indices are dropped according to the dropIndices

ReturnValue

Name Description
List<T>

list without elements which match the predicate

unwrapValues

fun <T> List<Optional<T>>.unwrapValues(): List<T>

Returns a list of values of type T, whereby the empty Optional are ignored.

Receiver

Name Description
List<Optional<T>>

ReturnValue

Name Description
List<T>

getValueResult

fun <V> List<V>.getValueResult(index: Int): Result<V, IllegalArgumentException>

Returns the value of listindex as Result.Success, if it exists, or as Result.Failure otherwise.

Receiver

Name Description
List<V>

the map on which the index is requested

Parameters

Name Description
index: Int

requested key to be accessed

ReturnValue

Name Description
Result<V, IllegalArgumentException>

Result of the request

getValueResult

fun <K : Any, V> Map<K, V>.getValueResult(key: K): Result<V, IllegalArgumentException>

Returns the value of mapkey as Result.Success, if it exists, or as Result.Failure otherwise.

Receiver

Name Description
Map<K, V>

the map on which the key is requested

Parameters

Name Description
key: K

requested key to be accessed

ReturnValue

Name Description
Result<V, IllegalArgumentException>

Result of the request

powerSet

fun <T> Set<T>.powerSet(): Set<Set<T>>

Returns the set of all possible subsets. See wikipedia article of power set.

Receiver

Name Description
Set<T>

the set for which all possible subsets are constructed

ReturnValue

Name Description
Set<Set<T>>

all possible subsets

combinations

fun <T> Set<T>.combinations(size: Int): Set<Set<T>>

Returns all possible subsets of this with size.

Receiver

Name Description
Set<T>

the set for which all possible subsets with size are constructed

Parameters

Name Description
size: Int

the number of elements per combination

ReturnValue

Name Description
Set<Set<T>>

all possible subsets of provided size