Maps
Map[K, V]
liftable add[K, V](map: expand Map[K, V], key: strict K, value: expand V): Map[K, V]
Associate a key
to a value
in this map, overriding the previous mapping for key
if existent.
Usage example:
in x: Events[(String, Int)]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
---
0: map = —
1: x = (A, 2)
1: map = A → 2
4: x = (B, 4)
4: map = A → 2, B → 4
7: x = (B, 8)
7: map = A → 2, B → 8
collectCount[T](events: Events[T]): Events[Map[T, Int]]
Counts the occurrences of each value in events
and returns a mapping of each value to its count.
Usage example:
in x: Events[String]
def map = Map.collectCount(x)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
---
0: map = —
1: x = A
1: map = A → 1
3: x = A
3: map = A → 2
6: x = C
6: map = A → 2, C → 1
def collectCount[T](events: Events[T]): Events[Map[T, Int]] =
StreamFunctions.fold(events, empty[T, Int], inc)
collectMax[K](key: Events[K], value: Events[Int]): Events[Map[K, Int]]
Get the maximum of value
, grouped by key
.
Usage example:
in x: Events[String]
in y: Events[Int]
def map = Map.collectMax(x, y)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream y: events
stream map: signal
---
0: map = —
1: x = A
1: y = 5
1: map = A → 5
3: y = 2
3: map = A → 5
4: x = C
5: y = 7
5: map = A → 5, C → 7
collectMin[A](key: Events[A], value: Events[Int])
Get the minimum of value
, grouped by key
.
Usage example:
in x: Events[String]
in y: Events[Int]
def map = Map.collectMin(x, y)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: signal
stream y: events
stream map: signal
---
0: map = —
1: x = A
1: y = 5
1: map = A → 5
3: y = 2
3: map = A → 2
4: x = C
5: y = 7
5: map = A → 2, C → 7
liftable contains[K, V](map: expand Map[K, V], key: strict K): Bool
Returns true if the given map
contains a mapping for the specified key
Usage example:
in x: Events[(String, Int)]
in y: Events[String]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def contains = Map.contains(map, y)
out contains
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream y: signal
stream contains: signal
---
0: map = —
1: x = (A, 2)
1: map = A → 2
1: y = B
1: contains = false
3: x = (B, 4)
3: map = A → 2, B → 4
3: contains = true
7: x = (B, 8)
7: map = A → 2, B → 8
7: y = C
7: contains = false
counting[A](events: Events[A])
Map every new value of events
to a unique integer ID
Usage example:
in x: Events[String]
def map = Map.counting(x)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
---
0: map = —
1: x = A
1: map = A → 1
3: x = C
3: map = A → 1, C → 2
6: x = A
6: map = A → 1, C → 2
def counting[A](events: Events[A]) = {
def counter: Events[Int] =
default(
if !contains(last(map, events), events)
then last(counter, events) + 1
else last(counter, events),
0)
def map: Events[Map[A, Int]] =
default(
if !contains(last(map, events), events)
then add(last(map, events), events, counter)
else last(map, events),
empty[A, Int])
map
}
empty[K, V]: Map[K, V]
Returns an empty map
without any element of type T
liftable fold[K, V, R](map: expand Map[K, V], start: lazy R, f: strict (expand R, strict K, expand V) => R): R
Applies a function f
on all values of the map
. Starting with the initial value start
the function f
is called for every pair of the map
with the last result and the current element value as arguments.
Usage example:
in x: Events[(String, Int)]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def sum = Map.fold(map, 0, (r: Int, k: String, v: Int) => r + v)
out sum
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream sum: signal
---
0: map = —
0: sum = 0
1: x = (A, 2)
1: map = A → 2
1: sum = 2
3: x = (B, 4)
3: map = A → 2, B → 4
3: sum = 6
7: x = (B, 8)
7: map = A → 2, B → 8
7: sum = 10
liftable get[K, V](map: expand Map[K, V], key: strict K): V
Get the corresponding value
for the given key
Usage example:
in x: Events[(String, Int)]
in y: Events[String]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def value = Map.get(map, y)
out value
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream y: signal
stream value: signal
---
0: map = —
1: x = (A, 2)
1: map = A → 2
2: y = A
2: value = 2
3: x = (B, 4)
3: map = A → 2, B → 4
3: y = B
3: value = 4
7: x = (B, 8)
7: map = A → 2, B → 8
7: value = 8
liftable getOrElse[K, V](map: expand Map[K, V], key: K, default: expand V): V
Get the value
associated with the key
if it exists in the map, and the default value otherwise.
Usage example:
in x: Events[(String, Int)]
in y: Events[String]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def result = Map.getOrElse(map, y, 42)
out result
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream y: signal
stream result: signal
---
0: map = —
1: x = (A, 2)
1: map = A → 2
1: y = A
1: result = 2
3: y = B
3: result = 42
5: x = (B, 4)
5: map = A → 2, B → 4
5: result = 4
liftable inc[K](counts: Map[K, Int], key: K): Map[K, Int]
Increments the value
of the given key
by one, or add a new entry key → 1
if the key
does not exist.
Usage example:
in x: Events[String]
def map: Events[Map[String, Int]] = fold(x, Map.empty[String, Int], Map.inc)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
---
0: map = —
1: x = A
1: map = A → 1
3: x = A
3: map = A → 2
6: x = C
6: map = A → 2, C → 1
liftable keys[K, V](map: expand Map[K, V]): List[K]
Returns the keys
of the elements in the given map
as list
Usage example:
in x: Events[(String, Int)]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def keys = Map.keys(map)
out keys
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream keys: signal
---
0: map = —
0: keys = —
3: x = (A, 2)
3: map = A → 2
3: keys = A
7: x = (B, 4)
7: map = A → 2, B → 4
7: keys = A, B
liftable map[A, B, C, D](m: expand Map[A, B], f: strict (strict A, expand B) => (C, D)): Map[C, D]
Applies a function to all elements in the map and returns a new map with the mapped elements. The applied function f
is able to map key and value. The order in which the mapping function is applied to the elements is non-deterministic. If f
maps several entries to the same key, the later mappings overwrite the previous ones. Usage example:
in x: Events[Map[Int, Int]]
def y: Events[Map[Int, Int]] = Map.map(l, (a: Int, b: Int) => (a + 1, b + 1))
out y
Trace example:
option timeDomain: [-1,7]
stream x: signal
stream y: signal
---
0: x = 1 → 2, 2 → 3
0: y = 2 → 3, 3 → 4
2: x = 1 → 0
2: y = 2 → 1
4: x = 1 → 3, 2 → 6
4: y = 2 → 4, 3 → 7
6: x = —
6: y = —
liftable remove[K, V](map: expand Map[K, V], key: strict K): Map[K, V]
Removes the entry matching the given key
Usage example:
in x: Events[String]
def filledMap = Map.add(Map.add(Map.empty[String, Int], "A", 2), "B", 4)
def map: Events[Map[String, Int]] = fold(x, filledMap, Map.remove)
out map
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
---
0: map = A → 2, B → 4
4: x = A
4: map = B → 4
7: x = C
7: map = B → 4
liftable size[K, V](map: expand Map[K, V]): Int
Returns the number of elements in the given map
Usage example:
in x: Events[(String, Int)]
def map: Events[Map[String, Int]] =
fold(x, Map.empty[String, Int],
(acc: Map[String, Int], v: (String, Int)) => Map.add(acc, v._1, v._2)
)
def size = Map.size(map)
out size
Trace example:
option timeDomain: [-1, 10]
stream x: events
stream map: signal
stream size: signal
---
0: map = —
0: size = 0
1: x = (A, 2)
1: map = A → 2
1: size = 1
4: x = B → 4
4: map = A → 2, B → 4
4: size = 2
7: x = (B, 8)
7: map = A → 2, B → 8
7: size = 2
atan, cos, floatToInt, intToFloat, log, max, min, pow, sin, tan, toString
average, boolFilter, bursts, burstsSince, const, constIf, count, default, defaultFrom, defined, delay, falling, filter, first, firstEvent, fold, isFirst, last, lift, lift1, lift2, lift3, lift4, lift5, maximum, merge, merge2, merge3, merge4, merge5, merge6, merge7, merge8, mergeUnit, mergeUnit2, mergeUnit3, mergeUnit4, minimum, nil, noEvent, on, period, prev, pure, reduce, resetCount, rising, runtime, sample, slift, slift1, slift2, slift3, slift4, slift5, sum, time, unitIf, zip, zip2, zip3, zip4, zip5