foldLeftWithKey<A> method

A foldLeftWithKey<A>(
  1. Order<K> order,
  2. A initial,
  3. A compose(
    1. A acc,
    2. K key,
    3. V value
    )
)

Apply compose to all the values of this Map sorted based on order on their key, and return the result of combining all the intermediate values.

Implementation

A foldLeftWithKey<A>(
  Order<K> order,
  A initial,
  A Function(A acc, K key, V value) compose,
) {
  final sorted = toSortedList(order);
  var result = initial;
  for (final item in sorted) {
    result = compose(result, item.key, item.value);
  }
  return result;
}