NSPL icon indicating copy to clipboard operation
NSPL copied to clipboard

Head and tail

Open Gert-dev opened this issue 5 years ago • 4 comments

Hello

I notice that there are no head and tail equivalents for functional programming. I did notice that there is a first and a drop($sequence, 1), which are equivalent in functionality. Perhaps it would be interesting to simply alias these two? They make implementing recursion in a functional way somewhat more expressive.

Also, thanks for this neat library! Of all the libraries that have some functional programming functionality, I must say this one seems the most extensive up until now. I even decided to prioritize implementing use statement generation for qualified functions and constants in Serenata (PHP language server) to smoothen use of this library.

Gert-dev avatar Jun 16 '19 18:06 Gert-dev

Apparently init is also missing, which returns all elements but the last, so it's the reverse of last and does what tail does, but for the last instead of the first element.

See also here or this very enlightening picture (by Miran Lipovača):

https://s3.amazonaws.com/lyah/listmonster.png

ghost avatar Jun 25 '19 13:06 ghost

Hey! Thanks for your suggestions. The functions are missing because I never needed them. I started this library when I was also working with Python and tried to copy some of the things I liked to PHP (and fix the weird API of the standard library).

I'll review @tominventisbe 's PRs this weekend.

ihor avatar Jul 04 '19 19:07 ihor

@ihor I suppose "this weekend" has already passed, and there are 3 PRs open that seem nice :-) Not that I need them right this instant or something, but for completion of the library's sake, could you review them? I like the zip-one for instance.

Lambik avatar Apr 24 '20 15:04 Lambik

@ihor I can help maintain the library if you do not have the time.

jtojnar avatar Dec 10 '21 01:12 jtojnar