dart-lang / dart-lang/language
Language suggestion: partial application for functions
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
It's just a suggestion for Dart lang, not a bug report. I did not find a way to publish my suggestion, so I file this here.
[Partial application](https://wiki.haskell.org/Partial_application) would be useful for functional programming.
With question mark `?` when calling a function, it turns a function into 'currying' similar to [a proposal in tc39](https://github.com/tc39/proposal-partial-application). For example,
```dart
foo(x, y, z) {
return (x - y) / z;
}
// currying with placeholders
var a = foo(8, 2, ?);
// same as
// var a = (z) => foo(8, 2, z);
a(2); //~> foo(8, 2, ?)(2) ~> foo(8, 2, 2) ~> 3
a(3); //~> foo(8, 2, ?)(3) ~> foo(8, 2, 3) ~> 2
a(6); //~> foo(8, 2, ?)(6) ~> foo(8, 2, 6) ~> 1
// useful for functional programming
[2, 3, 6].map(foo(8, 2, ?)); //~> [3, 2, 1]
[3, 2, 1].map(foo(?, 5, -1)); //~> [2, 3, 4]
[2, 3, 4].map(foo(9, ?, 1)); //~> [7, 6, 5]
// calling with multiple placeholders
foo(?, ?, 3)(9, 6); //~> foo(9, 6, 3) ~> 1
foo(?, ?, 3)(?, 6)(9); //~> 1
```
This feature would be useful to make functions ease-of-use in functional programming with Future/Promise and Stream/Rx, because the design of the function parameter ordering is irrelative.
```dart
request(query) // return a Future
.then(processData(?, options)) // pass data to processData(data, options)
.then(writeDataIntoDatabase(database, ?)); // pass data to writeDataIntoDatabase(database, data)
```
Contributor guide
Research direction
No repository files, tests, or entry points are named. Start by reviewing the partial-application examples and the linked Haskell and TC39 proposals, then check the project's language-design process; done would require an agreed Dart language proposal for placeholder syntax and its behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100