Attributes
Members list
Type members
Inherited and Abstract types
The names of the product elements
The names of the product elements
Attributes
- Inherited from:
- Mirror
The name of the type
The name of the type
Attributes
- Inherited from:
- Mirror
Value members
Concrete methods
Constructs an empty SortedMap.
Constructs an empty SortedMap.
Attributes
- Example
-
SortedMap.empty.toList === List.empty
Constructs a SortedMap from a list of key-value pairs, ordering it in strictly ascending order, in case when a key is presented multiple times, the first occurrence prevails.
Constructs a SortedMap from a list of key-value pairs, ordering it in strictly ascending order, in case when a key is presented multiple times, the first occurrence prevails.
Value parameters
- lst
-
the list of key-value pairs
Attributes
- Returns
-
a
SortedMapcontaining the key-value pairs from the list, with unique keys in sorted order - See also
-
unsafeFromList for an unfiltered unsafe version or fromStrictlyAscendingList for a faster stricter version
- Example
-
SortedMap.fromList(List.Cons(("b", 2), List.Cons(("a", 1), List.Nil))).toList === List.Cons(("a", 1), List.Cons(("b", 2), List.Nil)) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("a", 2), List.Nil))).toList === List.Cons(("a", 1), List.Nil)
Constructs a SortedMap from a list of key-value pairs, or fails if the list is not in strictly ascending order.
Constructs a SortedMap from a list of key-value pairs, or fails if the list is not in strictly ascending order.
Value parameters
- lst
-
the list of key-value pairs
Attributes
- Returns
-
a
SortedMapcontaining the key-value pairs from the list, or fails if the list is not in strictly ascending order - Throws
-
scalus.cardano.onchain.RequirementError
if the list is not in strictly ascending order
- See also
-
unsafeFromList for an unsafe fast or fromList for a safe slow versions that don't require strictly ascending order
- Example
-
SortedMap.fromStrictlyAscendingList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).toList === List.Cons(("a", 1), List.Cons(("b", 2), List.Nil)) SortedMap.fromStrictlyAscendingList(List.Cons(("a", 1), List.Cons(("a", 2), List.Nil))) // throws scalus.cardano.onchain.RequirementError
Constructs a SortedMap with a single key-value pair.
Constructs a SortedMap with a single key-value pair.
Value parameters
- key
-
the key to insert
- value
-
the value associated with the key
Attributes
- Returns
-
a
SortedMapcontaining the single key-value pair - Example
-
SortedMap.singleton("key", "value").toList === List.single(("key", "value"))
Provides a validating FromData instance for SortedMap[A, B] where both key and value types are instances of FromData. This method ensures that the keys are in strictly ascending order using Ord[A] instance for keys.
Provides a validating FromData instance for SortedMap[A, B] where both key and value types are instances of FromData. This method ensures that the keys are in strictly ascending order using Ord[A] instance for keys.
Attributes
- Throws
-
scalus.cardano.onchain.RequirementError
if the keys are not in strictly ascending order
Merges two SortedMaps into a new SortedMap containing keys from both maps. if a key is only present in left map, it is wrapped in These.This, if only in right map, it is wrapped in These.That, if a key is present in both maps, its values are wrapped in These.These. The resulting map is sorted by keys in strictly ascending order.
Merges two SortedMaps into a new SortedMap containing keys from both maps. if a key is only present in left map, it is wrapped in These.This, if only in right map, it is wrapped in These.That, if a key is present in both maps, its values are wrapped in These.These. The resulting map is sorted by keys in strictly ascending order.
This method is useful for combining two maps where you want to keep track of which keys are unique to each map and which keys are shared between
Value parameters
- lhs
-
the left-hand side
SortedMap - rhs
-
the right-hand side
SortedMap
Attributes
- Returns
-
a new
SortedMapcontaining keys from both maps, with values combined intoThese - Example
-
val map1 = SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))) val map2 = SortedMap.fromList(List.Cons(("b", 3), List.Cons(("c", 4), List.Nil))) SortedMap.union(map1, map2).toList === List.Cons(("a", These.This(1)), List.Cons(("b", These.These(2, 3)), List.Cons(("c", These.That(4)), List.Nil)))
Merges two SortedMaps into a new SortedMap and maps the combined values using a function.
Merges two SortedMaps into a new SortedMap and maps the combined values using a function.
Similar to union but additionally transforms the values. Keys that exist only in the left map have their values wrapped in These.This, keys that exist only in the right map have their values wrapped in These.That, and keys that exist in both maps have their values wrapped in These.These before being passed to the mapping function.
Value parameters
- f
-
the function to transform the combined values
- lhs
-
the left-hand side
SortedMap - rhs
-
the right-hand side
SortedMap
Attributes
- Returns
-
a new
SortedMapcontaining merged and transformed values - Example
-
val map1 = SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))) val map2 = SortedMap.fromList(List.Cons(("b", 3), List.Cons(("c", 4), List.Nil))) val combined = SortedMap.unionMap(map1, map2, { case These.This(x) => x * 10 // Only in left map case These.That(y) => y * 100 // Only in right map case These.These(x, y) => x + y // In both maps }) combined === List.Cons(("a", 10), List.Cons(("b", 5), List.Cons(("c", 400), List.Nil)))
Constructs a SortedMap in unsafe way from a list of key-value pairs assuming that it's in strictly ascending order without any validation.
Constructs a SortedMap in unsafe way from a list of key-value pairs assuming that it's in strictly ascending order without any validation.
Value parameters
- lst
-
the list of key-value pairs
Attributes
- Returns
-
a
SortedMapcontaining the key-value pairs from the list - See also
-
fromList or fromStrictlyAscendingList for safe versions
- Example
-
SortedMap.unsafeFromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).toList === List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))
Givens
Givens
Provides an Eq instance for SortedMap[A, B] where both key and value types are instances of Eq.
Provides an Eq instance for SortedMap[A, B] where both key and value types are instances of Eq.
Attributes
Provides a FromData instance for SortedMap[A, B] where both key and value types are instances of FromData. There is no validation that the keys are in strictly ascending order
Provides a FromData instance for SortedMap[A, B] where both key and value types are instances of FromData. There is no validation that the keys are in strictly ascending order
Attributes
Provides an Ord instance for SortedMap[A, B] where both key and value types are instances of Ord.
Provides an Ord instance for SortedMap[A, B] where both key and value types are instances of Ord.
Attributes
Provides a ToData instance for SortedMap[A, B] where both key and value types are instances of ToData.
Provides a ToData instance for SortedMap[A, B] where both key and value types are instances of ToData.
Attributes
Extensions
Extensions
Checks if a predicate holds for at least one key-value pair in the SortedMap.
Checks if a predicate holds for at least one key-value pair in the SortedMap.
Value parameters
- f
-
the predicate function to check
Attributes
- Returns
-
trueif the predicate holds for at least one pair,falseotherwise - Example
-
SortedMap.empty.exists(_ => true) === false SortedMap.singleton("key", "value").exists(_._1 === "foo") === false SortedMap.singleton("key", "value").exists(_._1 === "key") === true SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).exists(_._2 > 1) === true
Filters the key-value pairs of the SortedMap based on a predicate.
Filters the key-value pairs of the SortedMap based on a predicate.
Value parameters
- predicate
-
the predicate function to apply to each key-value pair
Attributes
- Returns
-
a new
SortedMapcontaining only the key-value pairs that satisfy the predicate - Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).filter(_._2 > 1).toList === List.Cons(("b", 2), List.Nil)
Filters the keys of the SortedMap based on a predicate.
Filters the keys of the SortedMap based on a predicate.
Value parameters
- predicate
-
the predicate function to apply to each key
Attributes
- Returns
-
a new
SortedMapcontaining only the key-value pairs where the key satisfies the predicate - Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).filterKeys(_ === "a").toList === List.Cons(("a", 1), List.Nil)
Filters the key-value pairs of the SortedMap based on a negated predicate.
Filters the key-value pairs of the SortedMap based on a negated predicate.
Value parameters
- predicate
-
the predicate function to apply to each key-value pair, negated
Attributes
- Returns
-
a new
SortedMapcontaining only the key-value pairs that do not satisfy the predicate - Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).filterNot(_._2 > 1).toList === List.Cons(("a", 1), List.Nil)
Optionally returns the first key-value pair that satisfies a predicate.
Optionally returns the first key-value pair that satisfies a predicate.
Value parameters
- predicate
-
the predicate function to apply to each key-value pair
Attributes
- Returns
-
an
Optioncontaining the first key-value pair that satisfies the predicate, orNoneif no such pair exists - Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).find(_._1 === "b") === Some(("b", 2)) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).find(_._1 === "c") === None
Finds the first key-value pair that satisfies a predicate and maps it to a new type.
Finds the first key-value pair that satisfies a predicate and maps it to a new type.
Value parameters
- predicate
-
the predicate function to apply to each key-value pair
Attributes
- Returns
-
an
Optioncontaining the result of mapping the first key-value pair that satisfies the predicate, orNoneif no such pair exists - Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).findMap { case ("b", v) => Some(v + 1) case _ => None } === Some(3) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).findMap { case ("c", v) => Some(v + 1) case _ => None } === None SortedMap.empty.findMap(_ => Some(1)) === None
Folds the SortedMap from the left, combining key-value pairs into a single value.
Folds the SortedMap from the left, combining key-value pairs into a single value.
Value parameters
- combiner
-
the function to combine the accumulated value with each key-value pair
- init
-
the initial value to start folding from
Attributes
- Returns
-
the final accumulated value after folding over all key-value pairs
- Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).foldLeft(0)(_ + _._2) === 3
Folds the SortedMap from the right, combining key-value pairs into a single value.
Folds the SortedMap from the right, combining key-value pairs into a single value.
Value parameters
- combiner
-
the function to combine the accumulated value with each key-value pair
- init
-
the initial value to start folding from
Attributes
- Returns
-
the final accumulated value after folding over all key-value pairs
- Example
-
SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).foldLeft(0)(_ + _._2) === 3
Checks if a predicate holds for all key-value pairs in the SortedMap.
Checks if a predicate holds for all key-value pairs in the SortedMap.
Value parameters
- f
-
the predicate function to check
Attributes
- Returns
-
trueif the predicate holds for all pairs,falseotherwise - Example
-
SortedMap.empty.forall(_ => true) === true SortedMap.singleton("key", "value").forall(_._1 === "foo") === false SortedMap.singleton("key", "value").forall(_._1 === "key") === true SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).forall(_._2 > 0) === true
Checks if the SortedMap is empty.
Checks if the SortedMap is empty.
Attributes
- Returns
-
trueif the map is empty,falseotherwise - Example
-
SortedMap.empty.isEmpty === true SortedMap.singleton("key", "value").isEmpty === false
Returns a list of keys in the SortedMap.
Returns a list of keys in the SortedMap.
Attributes
- Returns
-
a list containing all keys in the map
- Example
-
SortedMap.empty.keys === List.empty SortedMap.singleton("key", "value").keys === List.single("key") SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).keys === List.Cons("a", List.Cons("b", List.Nil))
Returns the number of key-value pairs in the SortedMap.
Returns the number of key-value pairs in the SortedMap.
Attributes
- Returns
-
the number of key-value pairs in the map
- Example
-
SortedMap.empty.length === 0 SortedMap.singleton("key", "value").length === 1
Maps the values of the SortedMap using a function.
Maps the values of the SortedMap using a function.
Value parameters
- f
-
the function to apply to each value
Attributes
- Returns
-
a new
SortedMapwith the same keys and transformed values - Example
-
SortedMap.singleton("key", 1).mapValues(_ + 1).toList === List.single(("key", 2)) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).mapValues(_ * 2).toList === List.Cons(("a", 2), List.Cons(("b", 4), List.Nil))
Checks if the SortedMap is non-empty.
Checks if the SortedMap is non-empty.
Attributes
- Returns
-
trueif the map is non-empty,falseotherwise - Example
-
SortedMap.empty.nonEmpty === false SortedMap.singleton("key", "value").nonEmpty === true
Returns the size of the SortedMap, which is the same as its length.
Returns the size of the SortedMap, which is the same as its length.
Attributes
- Returns
-
the size of the map
- Example
-
SortedMap.empty.size === 0 SortedMap.singleton("key", "value").size === 1
Returns a list of values in the SortedMap.
Returns a list of values in the SortedMap.
Attributes
- Returns
-
a list containing all values in the map
- Example
-
SortedMap.empty.values === List.empty SortedMap.singleton("key", "value").values === List.single("value") SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).values === List.Cons(1, List.Cons(2, List.Nil))
Retrieves the value associated with a key, or fails if the key is not present.
Retrieves the value associated with a key, or fails if the key is not present.
Value parameters
- key
-
the key to retrieve the value for
Attributes
- Returns
-
the value associated with the key
- Throws
-
NoSuchElementException
if the key is not present in the map
- Example
-
SortedMap.singleton("key", "value").at("key") === "value" SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).at("a") === 1 SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).at("c") // throws NoSuchElementException SortedMap.empty.at("key") // throws NoSuchElementException
Checks if the SortedMap contains a key.
Checks if the SortedMap contains a key.
Value parameters
- key
-
the key to check for existence
Attributes
- Returns
-
trueif the map contains the key,falseotherwise - Example
-
SortedMap.empty.contains("key") === false SortedMap.singleton("key", "value").contains("key") === true SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).contains("a") === true SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).contains("c") === false
Deletes a key-value pair from the SortedMap by key.
Deletes a key-value pair from the SortedMap by key.
Value parameters
- key
-
the key to delete
Attributes
- Returns
-
a new
SortedMapwith the key-value pair removed, if it existed - Example
-
SortedMap.empty[String, BigInt].delete("key") === SortedMap.empty SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).delete("a").toList === List.Cons(("b", 2), List.Nil) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).delete("c").toList === List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))
Optionally returns the value associated with a key.
Optionally returns the value associated with a key.
Value parameters
- key
-
the key value
Attributes
- Returns
-
an option value containing the value associated with
keyin this map, orNoneif none exists. - Example
-
SortedMap.empty.get("key") === None SortedMap.singleton("key", "value").get("key") === Some("value") SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).get("a") === Some(1) SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).get("c") === None
Insert a key-value pair into the SortedMap, maintaining the sorted order without duplication. * If the key already exists, it updates the value. * @param key the key to insert
Insert a key-value pair into the SortedMap, maintaining the sorted order without duplication. * If the key already exists, it updates the value. * @param key the key to insert
Value parameters
- value
-
the value associated with the key * @return a new
SortedMapwith the key-value pair inserted
Attributes
- Example
-
SortedMap.empty.insert("key", "value") === SortedMap.singleton("key", "value") SortedMap.singleton("key", "value").insert("key", "newValue") === SortedMap.singleton("key", "newValue") SortedMap.fromList(List.Cons(("a", 1), List.Cons(("b", 2), List.Nil))).insert("c", 3).toList === List.Cons(("a", 1), List.Cons(("b", 2), List.Cons(("c", 3), List.Nil)))