Ramda: Why "take" behaves that way?

Created on 31 Oct 2019  ·  3Comments  ·  Source: ramda/ramda

I don't get why take in this case
Снимок экрана 2019-10-31 в 16 53 35
will produce that result
Снимок экрана 2019-10-31 в 16 53 41
instead of
Снимок экрана 2019-10-31 в 16 55 42
Is it the right behavior?

Most helpful comment

@makarkotlov If you'd like to return the first element, try head.

All 3 comments

yes it is correct. Consider the case where you have

const xs = [[1, 2], [3, 4], [5, 6]]
take(2, xs) //=> [[1, 2], [3, 4]]

therefore,

take(1, xs) //=> [[1, 2]] 

the contract of take is that you tell it how many elements to take and a list to take from, and it will return a list of all the elements you asked for.

@makarkotlov If you'd like to return the first element, try head.

Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjohansen picture cjohansen  ·  4Comments

DanielTimLee picture DanielTimLee  ·  3Comments

MadDeveloper picture MadDeveloper  ·  3Comments

Antontelesh picture Antontelesh  ·  3Comments

woss picture woss  ·  3Comments