What is the Kotlin equivalent for Dart's List.expand() method?

Viewed 322

In Dart, List.expand() allows mapping each element of the existing List into zero, one, or multiple elements, and then assemble them as a new Iterable. Such as,

var a=[1,2,3];
var b = a.expand((i)=>List.generate(i,(_)=>i.toString())).toList();
print(b.toString());
//Output: [1, 2, 2, 3, 3, 3]

Basically an enhanced map() function allows "one to many" mapping

What is the Kotlin equivalent if I want to do the same? I failed to find corresponding method in Kotlin collections.

1 Answers
Related