prelude-ls
prelude-ls copied to clipboard
Call function arguments in List functions with multiple arguments (element, index, array)
Native JS [].map
and [].forEach
call the given function with function(element, index, array)
. I think the List functions that take functions in prelude would benefit from the same thing - right now they only call the given functions with function(element)
in most cases. Providing the index and array would give a lot more flexibility.
+1, it seems like this is a must-have for prelude's list functions to be an alternative to underscore
The issue is with using map
on a list of curried functions to create new functions, but maybe that is a small use case.
Could you give an example of how to use zips to achieve this effect, as mentioned in #21? I'm confused how to create a readable pattern for this, both with list functions and object functions.
I would think that use case is less common than mapping through a list or object of non-function values or non-curried functions. Maybe my head is just stuck in my ways, but I'm trying to achieve something with similar readability to:
map ((val, key) -> "#key is #val"), <[ foo bar baz ]> #=> ["0 is foo", "1 is bar", "2 is baz"]
I'm leaning toward changing it. As the change will not be backwards compatible, it would be with prelude.ls 2.0.0
Right, for now I'm just using Daiz's versions renamed to map-at
, filter-at
, etc.
Could you give an example of how to use zips to achieve this effect, as mentioned in #21? I'm confused how to create a readable pattern for this, both with list functions and object functions.
I would think that use case is less common than mapping through a list or object of non-function values or non-curried functions. Maybe my head is just stuck in my ways, but I'm trying to achieve something with similar readability to:
map ((val, key) -> "#key is #val"), <[ foo bar baz ]> #=> ["0 is foo", "1 is bar",
zip-with ((i, val) -> "#i is #val") [1 to 3] <[ foo bar baz ]>
Also, I think it'd be better to not break compatibility. and just offer additional functions if you need an index.
If you want to get the index, you can use obj-to-pairs
on an array (this will get the index as a string):
map (([key, val]) -> "#key is #val"), obj-to-pairs <[ foo bar baz ]>
Adding key access would also be a welcomed addition for Obj.* versions such as Obj.map and Obj.each
One benefit is easier migration from other toolbelt like lodash.