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

Feature Request: map, filter, fold, zip and other functional operators #319

Closed
viclib opened this issue May 25, 2013 · 13 comments
Closed

Feature Request: map, filter, fold, zip and other functional operators #319

viclib opened this issue May 25, 2013 · 13 comments

Comments

@viclib
Copy link
Contributor

viclib commented May 25, 2013

Considering how those are recurrent functions in FP, I propose we could have operators for them.

[1 to 5] :> (^2) => [1 4 9 16 25]
[1 to 5] ?> (>3) => [4 5]
[1 to 5] <> (+) => 15
[1 2 3] &> [4 5] => [[1 4] [1 5] [2 4] [2 5] [3 4] [3 5]]
[dog1, dog2] .> bark! => [dog1.bark(), dog2.bark()]

This way,

[1 to 5] |> map (^2) |> filter even |> fold (+), 0
becomes
[1 to 5] :> (^2) ?> even <> (+)

strs |> map (.toUpperCase!)
becomes
strs.>toUpperCase!

@vendethiel
Copy link
Contributor

"LiveScript doesn't target APL programmers" :p.
Use prelude-ls

@viclib
Copy link
Contributor Author

viclib commented May 25, 2013

Just what makes an operator for map inferior to all other operators we have already?

@viclib viclib closed this as completed May 25, 2013
@viclib viclib reopened this May 25, 2013
@vendethiel
Copy link
Contributor

  1. ?> is already an operator
  2. we don't need operators for everything, especially with prelude-ls
  3. The "map apply" operator is the only one I think is interesting, but I'd prefer a syntax like groovy's *., see Array spread operator satyr/coco#187

@viclib
Copy link
Contributor Author

viclib commented May 25, 2013

Just again, what's the argument to have operators for things that are barely used such as >? and <?, but not for the most used functions in FP?

@vendethiel
Copy link
Contributor

I don't know why @satyr wanted wanted string comparison operators, maybe perl6 has them :p.

@viclib
Copy link
Contributor Author

viclib commented May 25, 2013

What do you mean with string comparison operators?

@vendethiel
Copy link
Contributor

@gkz
Copy link
Owner

gkz commented May 25, 2013

I think having a standard library (prelude.ls) with these features is the way to go. We currently have too many operators, and I'll be removing some of the less used/obscure/redundant ones in the future.

@gkz gkz closed this as completed May 25, 2013
@viclib
Copy link
Contributor Author

viclib commented May 26, 2013

okay comma that apostrophe s fair period this remembers the quote punctuation quote argument in favor of keeping the quote function quote and quote return quote keywords in javascript period punctuation is important comma for sure semicolon that apostrophe s exactly why i just hope you remember there is a reason we use symbols instead of words for punctuation period parenthesis colon

@goto-bus-stop
Copy link

@viclib, but ^, <, !can use sigils for ██! Symbols like :>, <>, &> look somewhat random (or at the very least, non-obvious), and are definitely more readable when written using .map, .filter and such or the prelude.ls versions

@rightfold
Copy link

Speaking of APL programmers, I propose allowing embedding of APL code in LiveScript:

sort←{1≥⍴⍵:⍵⋄p←⊃⍵⋄r←1↓⍵⋄(∇r/⍨r≤p),p,(∇r/⍨r>p)}
⍳10 |> shuffle |> scanl (-) <|⍨ sort |> console~log

Even if only to make new LiveScript programmers go even more ⍨ than they did before.

@phanimahesh
Copy link

I could never program in APL, but just for the lulz, APL in ls sounds great! :P

@ozra
Copy link

ozra commented May 6, 2015

Yaeh, I'd loove to debug that code!

2015-05-02 16:25 GMT+02:00 J Phani Mahesh [email protected]:

I could never program in APL, but just for the lulz, APL in ls sounds
great! :P


Reply to this email directly or view it on GitHub
#319 (comment).

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

7 participants