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

enhance(func) Extend compose to suport N functions #448

Merged
merged 4 commits into from
Dec 28, 2022
Merged

enhance(func) Extend compose to suport N functions #448

merged 4 commits into from
Dec 28, 2022

Conversation

broma0
Copy link
Contributor

@broma0 broma0 commented Dec 19, 2022

Previously, func.compose only supported two functions, as in:

compose(print, string.upper)("hello") -- prints "HELLO"

This commit enables any number of functions to be composed by internally leveraging tablex.reduce to repeatedly apply functions.

For example:

compose(bind1(add, 10), bind1(mul, 5), bind(div, _1, 3))(9)
-- prints "25"

One can also pass functions as a table:

compose({ bind1(add, 10), bind1(mul, 5), bind(div, _1, 3) })(9)
-- prints "25"

Previously, func.compose only supported two functions, as in:

  compose(print, string.upper)("hello") -- prints "HELLO"

This commit enables any number of functions to be composed by internally
leveraging tablex.reduce to repeatedly apply functions.

For example:

  compose(bind1(add, 10), bind1(mul, 5), bind(div, _1, 3))(9)
    -- prints "25"

One can also pass functions as a table:

  compose({ bind1(add, 10), bind1(mul, 5), bind(div, _1, 3) })(9)
    -- prints "25"
Copy link
Member

@Tieske Tieske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the PR. Missing are tests, and a changelog entry. Can you add those?

lua/pl/func.lua Outdated Show resolved Hide resolved
@broma0
Copy link
Contributor Author

broma0 commented Dec 24, 2022

@Tieske - Thanks for the reminder regarding the tests and the advice about the table argument. I've updated the code accordingly.

@Tieske Tieske merged commit 7e67bcb into lunarmodules:master Dec 28, 2022
@Tieske
Copy link
Member

Tieske commented Dec 28, 2022

@broma0 thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants