

Parameters action - function that takes the index of a character and the character itself and performs the action on the character. Actually it isn't - the documentation says it creates an immutable view of the list. forEachIndexed Common JVM JS Native 1.0 inline fun CharSequence.forEachIndexed( action: (index: Int, Char) -> Unit) (source) Performs the given action on each character, providing sequential index with the character. Starting with Dart 2.7, you can use extension methods to extend the functionalities of Iterable instead of having to write helper functions: extension ExtendedIterable on Iterable ) would be really inefficient because it looks like it is converting the list to a map. Print('index: $index, element: $element') Note that unlike javascript's array.map() or C#'s IEnumerable.Select(), the index is the first argument, not the second argument of the callback: import 'package:collection/collection.dart' įinal inputs = įinal indexes = inputs.mapIndexed((index, element) => index).toList()


You can use the mapIndexed or forEachIndexed extension methods from the collection package.
