Skip to content

Conversation

@stackoverflow
Copy link
Contributor

No description provided.

@StefMa
Copy link
Contributor

StefMa commented Nov 25, 2025

Who ever wants to use a compose function? It's super complicated to read/understand 🙈

Copy link
Member

@bioball bioball left a comment

Choose a reason for hiding this comment

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

Can you describe the motivation for this?
The language already provides the pipe operator, which provides similar functionality.
So, to add this, I think we should have some rationale for why an additional API makes sense.

local addOne = (x) -> x + 1
local double = (x) -> x * 2

res1 = 5 |> addOne |> double

Might be good to have a SPICE.

@stackoverflow
Copy link
Contributor Author

Can you describe the motivation for this? Why not just use the pipe operator?

local addOne = (x) -> x + 1
local double = (x) -> x * 2

res1 = 5 |> addOne |> double

Might be good to have a SPICE.

The pipe operator is function application not composition. If you are providing functions for others to use you don't know what they'll be applied to.
Sure you can just create another lambda yourself:

local addOneAndDouble = (x) -> double.apply(addOne.apply(x))

But using a function for that is more ergonomic and readable, specially when there's a bunch of lambdas to be connected.

local addOneAndDouble = addOne.andThen(double)

These functions are similar to the same named ones in Scala, or the . operator in Haskell, the >> and << operators in F#, etc.

I don't think we need a spice for them, specially because they don't pollute the global namespace.

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.

4 participants