gkz / prelude-ls

prelude.ls is a functionally oriented utility library - powerful and flexible, almost all of functions are curried. It is written in, and is the recommended base library for, http://livescript.net
http://preludels.com/
MIT License
424 stars 59 forks source link

List.append (curried) for appending one list to another #88

Closed atifaziz closed 9 years ago

atifaziz commented 9 years ago

This:

append = (xs, ys) --> ys.concat xs

would make writing the following possible:

[1 2 3] |> append [4 5 6]

Signature: [a] → [a] → [a]

Unless, of course, I've missed something in the LiveScript bag of tricks.

anko commented 9 years ago

(++)?

[1 2 3] |> (++) [4 5 6][ 4, 5, 6, 1, 2, 3 ].

atifaziz commented 9 years ago

@anko Great suggestion (I have forgotten about ++) and I can live with that for now. The only difference is that (and which I also forgot to specify in my original comment) it would behave more like:

[1 2 3] |> append [4 5 6] #=> [1, 2, 3, 4, 5, 6]

But I could partially apply ++ with a placeholder as follows to get that effect as part of a pipeline:

[1 2 3] |> ((++) _, [4 5 6])

That would make the definition of append just a flip of ++ arguments:

append = (xs, ys) --> ys ++ xs

…boiling down to just:

append = flip (++)

If the prelude maintainers feel append doesn't add any value (even for readability) then I wouldn't be completely annoyed or disappointed if this issue is closed. :smirk: Then again, not sure where you draw the with one-liner functions.

gkz commented 9 years ago

I think ++ is good enough.

[1 2 3] |> (++ [4 5 6])
#=> [1,2,3,4,5,6]
atifaziz commented 9 years ago

@gkz Okay, I clearly forgot the first of the two examples listed in the docs:

(+ 2) 4         #=> 6
(*) 4 3         #=> 12

It would've done the job in the first place. I don't know why I kept insisting on the second form; could be muscle memory from F# that requires the second form.