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

Add curryN to the helper functions #20

Merged
merged 1 commit into from
Jan 10, 2017
Merged

Add curryN to the helper functions #20

merged 1 commit into from
Jan 10, 2017

Conversation

evilsoft
Copy link
Owner

@evilsoft evilsoft commented Jan 8, 2017

Limit Dem

This PR address issue#10.

It adds a curryN function to limit the number of arguments to a function or deal with N-ary functions or defaulted arguments.

// limit to default
const times10 = curryN(1,
  (x, y=10) => x * y
)
times10(23) // 230

// arg spread
const scaleSum = curryN(4,
  (s, ...args) => args.reduce((x, y) => x + y, 0) * s
)
const doubleSum = scaleSum(2)

scaleSum(10, 3)(4, 5) // 120
doubleSum(3, 4)(5) // 24

// N-ary
const maxOf3 = curryN(3, Math.max)
maxOf3(3)(20)(0) // 20

This function will not keep currying until a non-function is returned like curry does.

const f =  curryN(3,
  (x, y) => z => [ x, y, z ]

// the last argument is applied to the outer function and
// therefore thrown away, resulting in the inner function
// being returned.
f(3, 4, 5) // z => ...

@flintinatux
Copy link

I like the look of this. Since it's OSS, you oughta hook up some free Travis for your specs to check PR's.

@evilsoft
Copy link
Owner Author

evilsoft commented Jan 9, 2017

@flintinatux 🍬 idea!

@evilsoft
Copy link
Owner Author

@evilsoft evilsoft merged commit bc7c55f into master Jan 10, 2017
@evilsoft evilsoft deleted the curryN branch January 10, 2017 03:46
@evilsoft evilsoft added this to the v0.1.1 milestone Jan 14, 2017
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

Successfully merging this pull request may close these issues.

2 participants