COMMUNITY

How to get first number of elements out from list

How do I take the first items out in a list in Haxe?

I am most used with the C# LINQ Take, which I think is the same as javascript’s const slicedArray = array.slice(0, n);

(I don’t want to do it imperatively)

Haxe also has a slice() method on its Array class.

https://api.haxe.org/Array.html#slice

Yeah, I used saw that. I will be using Array instead List.
Is there a nice way convert between them, and any reason I shouldn’t completely use Array?

Chances are that using Array will be fine. There will be situations where List gives better performance, but most of the time, you probably won’t be able to measure a difference.

What is the best way to convert from List<T> to Array<T>…?

Lambda.array(list);

or

using Lambda;
list.array();