map<A, B> function
- B f(
- A
Returns a function that takes an ImmutableList<A>
and maps each item
in the list using the provided function f
to produce a new ImmutableList<B>
.
This operation does not modify the original list but instead produces a new list with items of a potentially different type.
Usage:
var myList = ImmutableList([1, 2, 3, 4, 5]);
var mapToDouble = map<int, double>((item) => item * 2.5);
var newList = mapToDouble(myList); // Returns ImmutableList([2.5, 5.0, 7.5, 10.0, 12.5])
- Parameter
f
: The mapping function that takes an item of typeA
and returns a new item of typeB
. - Returns: A function that processes an
ImmutableList<A>
and produces a newImmutableList<B>
with mapped items.
Implementation
ImmutableList<B> Function(ImmutableList<A>) map<A, B>(B Function(A) f) =>
(ImmutableList<A> list) => ImmutableList(list._items.map(f).toList());