Field

interface Field<out T>

A field is a map of messages where the key is the ID of a node and T the associated value.

Parameters

T

the type of the field.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val localId: ID

The ID of the local node.

Link copied to clipboard
abstract val localValue: T

The value associated with the localId.

Functions

Link copied to clipboard
abstract fun asSequence(): Sequence<Pair<ID, T>>

Transform the field into a map.

Link copied to clipboard
abstract fun excludeSelf(): Map<ID, T>

Exclude the local node from the field.

Link copied to clipboard
abstract operator fun get(id: ID): T

Get the value associated with the id. Raise an error if the id is not present in the field.

Link copied to clipboard
fun <T> Field<T>.hood(transform: (T, T) -> T): T

Reduce the elements of a field using the transform function.

Link copied to clipboard
fun <T, R> Field<T>.hoodInto(initial: R, transform: (R, T) -> R): R

Reduce the elements of a field starting with a initial value and a transform function.

Link copied to clipboard
open fun <B> map(transform: (T) -> B): Field<B>

Map the field using the transform function.

Link copied to clipboard
abstract fun <B> mapWithId(transform: (ID, T) -> B): Field<B>

Map the field using the transform function.

Link copied to clipboard
fun <T : Comparable<T>> Field<T>.max(includingSelf: Boolean = true): T

Get the maximum value of a field.

Link copied to clipboard
fun <T : Comparable<T>> Field<T>.min(includingSelf: Boolean = true): T

Get the minimum value of a field.

Link copied to clipboard
operator fun <T : Number> Field<T>.minus(value: T): Field<T>

Operator to subtract a value to all the values of the field.

operator fun <T : Number> Field<T>.minus(other: Field<T>): Field<T>

Subtract a field with other field. The two fields must be aligned, otherwise an error is thrown.

Link copied to clipboard
operator fun <T : Number> Field<T>.plus(value: T): Field<T>

Operator to sum a value to all the values of the field.

operator fun <T : Number> Field<T>.plus(other: Field<T>): Field<T>

Sum a field with other field. The two fields must be aligned, otherwise an error is thrown.

Link copied to clipboard
fun <T> Field<T>.reduce(includingSelf: Boolean = true, transform: (accumulator: T, T) -> T): T

Reduce the elements of the field using the transform function.

Link copied to clipboard
abstract fun toMap(): Map<ID, T>

Returns a map representing the field.