foldRightWithKey<A> method

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

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

Implementation

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