Skip to content

Should all operators be functions-that-return-functions?  #2

@njlr

Description

@njlr

To achieve a friendly syntax for operators with parameters, we use a pattern where the library provides a function-that-returns-a-function.

> seq.map
[Function]

> seq.map(x => x * 2)
[Function]

We do not do this for operators without parameters.

> seq.toArray
[Function]

Some operators have parameters, but each has a default value:

> seq.unique
[Function]

> seq.unique()
[Function]

This makes operator usage somewhat inconsistent:

[ 1, 2, 3 ]
  |> map(x => x * 2) // Parentheses to wrap parameters
  |> unique() // Parentheses required because we have default arguments
  |> toArray; // No parentheses, because this is not a function-that-returns-a-function

Perhaps it should look like this instead?

[ 1, 2, 3 ]
  |> map(x => x * 2) 
  |> unique() 
  |> toArray(); // Parentheses required for all operators

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions