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

Reduce and where #37

Closed
FlorianRappl opened this issue Jun 17, 2016 · 0 comments
Closed

Reduce and where #37

FlorianRappl opened this issue Jun 17, 2016 · 0 comments
Assignees
Milestone

Comments

@FlorianRappl
Copy link
Owner

Two new functions should be handy in many scenarios: where and reduce. The latter is a nice addition to map, which transforms elements (providing a mapping from the source to the target). It will reduce the N elements to a single item.

The where function is essentially filter in JS (or Where in LINQ).

reduce will work with matrices and objects. It requires three arguments: a function, a start value, and an object to operate on.

new { a: 5, b: 9, c: 10 } | reduce(add, 0) // 0 + 5 + 9 + 10
[1, 3, 10] | reduce(subtract, 10) // 10 - 1 - 3 - 10

where will work with matrices and objects. It requires two arguments: a function and an object to operate on.

new { a: 5, b: 9, c: 10 } | where(x => x > 8) // new { b: 9, c: 10 }
[1, 3, 10] | where(greater(2)) // [3, 10]

Remark In v0.9 I will change greater, less, etc. to be actually like greater(x, y) == y > x. Right now (v0.8) it is greater(x, y) == x > y. There are some other functions that need to be reversed to be better for chaining, e.g., subtract, pow, or divide.

@FlorianRappl FlorianRappl added this to the 0.9 milestone Jun 17, 2016
@FlorianRappl FlorianRappl self-assigned this Jun 17, 2016
This was referenced Jun 18, 2016
FlorianRappl added a commit that referenced this issue Jun 19, 2016
FlorianRappl added a commit that referenced this issue Jun 19, 2016
FlorianRappl added a commit that referenced this issue Jun 19, 2016
FlorianRappl added a commit that referenced this issue Jun 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant