zipWithNextTransform<R> method

KtList<R> zipWithNextTransform<R>(
  1. R transform(
    1. T a,
    2. T b
    )
)

Returns a list containing the results of applying the given transform function to an each pair of two adjacent elements in this collection.

The returned list is empty if this collection contains less than two elements.

Implementation

KtList<R> zipWithNextTransform<R>(R Function(T a, T b) transform) {
  final i = iterator();
  if (!i.hasNext()) {
    return emptyList();
  }
  final list = mutableListOf<R>();
  var current = i.next();
  while (i.hasNext()) {
    final next = i.next();
    list.add(transform(current, next));
    current = next;
  }
  return list;
}