question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Have all `compose`/`pipe` functions return only unary functions

See original GitHub issue

Description/Location

location: ‘./helpers/aThing.js’ description: The current implementation allows the ability to apply any number of arguments to the head function in the composition/pipe. While this is very 🌽venient at times, it has been know to lead to hard to reason about compositions and many time unnecessary argument juggling. It also provides limits on how a composed function is curried.

By limiting this to just a unary function, it removes the ability to get into a juggling mess and can also allow us to properly curry the function that is returned for cases like:

// pluck :: String -> [ a ] -> Maybe b
const pluck = curry(
  key => map(prop(key))
)

pluck('id', [ { id: 2 } ])
//=> [ Just 2 ]

becomes:

// pluck :: String -> [ a ] -> Maybe b
const pluck = 
 compose(map, prop)

While is maybe different then what we are used to from the standard in JS in most libs, if you look at the code and remember that x => f(g(x)) is the same thing as compose(f, g) see how these are actually equivalent. Now people who for some reason have not adopted compose and STILL use pipe for one reason or another, it may be harder for this to click when writing and maintaining code. But as shown above, these are equivalent and should be allowed to be implemented that way.

This is more of a proposal to get peoples opinions and thoughts. Would love to get some emoji reactions to this, and if possible a comment on why you feel the way you do.

Task List

  • Build out a task list if enough people understand why and the implications.

For more information, see the CONTRIBUTING guide.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
evilsoftcommented, Aug 5, 2019

Nah. I think we are good on closing this.

0reactions
dalefrancis88commented, Jul 31, 2019

@evilsoft @karthikiyengar knowing that we can curry the composition and we also have compose2 now to get this to work, do we still want this as an addressable issue given that this would be a quite serious breaking change were we to implement it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Functional Programming Tutorial - YouTube
Learn how to create pipe functions and compose functions in this Javascript functional programming tutorial. Functional programming needs ...
Read more >
My favorite ways to write pipe and compose in JavaScript
All the above snippets, by the way, are unary. Each function may only accept a single argument. If your pipeline's first function must...
Read more >
Reconsider changes to pipe and compose #1318 - GitHub
If we stick to the mathematic definition of composition then we can assume that all functions are unary and these problem go away....
Read more >
A quick introduction to pipe() and compose() in JavaScript
The concept of pipe is simple — it combines n functions. It's a pipe flowing left-to-right, calling each function with the output of...
Read more >
Function Composition in Javascript - Oğuzhan Olguncu
In this article we`ll deep dive into function composition, pipes, currying and partial applications with examples from real world.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found