Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cons (push) opposite: unshift? #24

Closed
oluckyman opened this issue May 9, 2019 · 2 comments
Closed

cons (push) opposite: unshift? #24

oluckyman opened this issue May 9, 2019 · 2 comments

Comments

@oluckyman
Copy link

Is there the opposite for cons? which will insert an element into beginning?
And if no, what's the shades-style to achieve it?

@oluckyman oluckyman changed the title cons (push) alternative: unshift? cons (push) opposite: unshift? May 9, 2019
@jamesmcnamara
Copy link
Owner

As of shades@2.1.0-beta.1, there's an unshift function!

> unshift(1)([2, 3, 4])
[1, 2, 3, 4]

You can grab it by doing

npm install shades@beta

Or if you want to stick with the stable branch, you can do:

> prepend([1])([2, 3, 4])
[1, 2, 3, 4]

Note that prepend requires that the first element be a list as well.

@oluckyman
Copy link
Author

ah, thanks! missed the prepend or was not aware that it's what I need. Ended up by using

x => xs => [x, ...xs]

which is pretty concise too.

offtop suggestion: Table of contents for API would be helpful. To see all the methods at a glance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants