Daniel Robinson
Daniel Robinson

Reputation: 14858

Dart, how to transform from one iterable to another?

I have something like:

Element html = DivElement();

and I add some children from a list of types which have a html element property:

for(var base in bases){

    html.children.add(base.html);

}

Is there a way of doing this in Dart like you can in C# syntax?

html.children.addAll(base.select(o => o.html)); //no need for a for-in loop now

Upvotes: 0

Views: 235

Answers (1)

Daniel Robinson
Daniel Robinson

Reputation: 14858

use map:

html.children.addAll(bases.map((o) => o.html));

done.

Upvotes: 3

Related Questions