onEach method

KtSet<T> onEach(
  1. void action(
    1. T item
    )
)

Performs the given action on each element. Use with cascade syntax to return self.

final result = setOf("a", "b", "c") .onEach(print) .map((it) => it.toUpperCase()) .getOrNull(0); // result: A

Without the cascade syntax (..) KtListExtensions.getOrNull wouldn't be available.

Implementation

KtSet<T> onEach(void Function(T item) action) {
  for (final element in iter) {
    action(element);
  }
  return this;
}