mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Multi-Argument Functions As Syntactic Sugar as a reasonml til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_613 TILs and counting..._
|
_614 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -441,6 +441,7 @@ _613 TILs and counting..._
|
|||||||
### ReasonML
|
### ReasonML
|
||||||
|
|
||||||
- [Exhaustive Pattern Matching Of List Variants](reason/exhaustive-pattern-matching-of-list-variants.md)
|
- [Exhaustive Pattern Matching Of List Variants](reason/exhaustive-pattern-matching-of-list-variants.md)
|
||||||
|
- [Multi-Argument Functions As Syntactic Sugar](reason/multi-argument-functions-as-syntactic-sugar.md)
|
||||||
- [Pattern Match On Exceptions](reason/pattern-match-on-exceptions.md)
|
- [Pattern Match On Exceptions](reason/pattern-match-on-exceptions.md)
|
||||||
- [String Interpolation With Integers And Sprintf](reason/string-interpolation-with-integers-and-sprintf.md)
|
- [String Interpolation With Integers And Sprintf](reason/string-interpolation-with-integers-and-sprintf.md)
|
||||||
|
|
||||||
|
|||||||
33
reason/multi-argument-functions-as-syntactic-sugar.md
Normal file
33
reason/multi-argument-functions-as-syntactic-sugar.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Multi-Argument Functions As Syntactic Sugar
|
||||||
|
|
||||||
|
When writing a multi-argument function, like the following `adder` function:
|
||||||
|
|
||||||
|
```reason
|
||||||
|
let adder = (x, y) => x + y;
|
||||||
|
|
||||||
|
adder(2, 3); /* => 5 */
|
||||||
|
```
|
||||||
|
|
||||||
|
We are utilizing a syntactic sugar of the function syntax. The same function
|
||||||
|
can be written as such:
|
||||||
|
|
||||||
|
```reason
|
||||||
|
let adder = (x) => (y) => x + y;
|
||||||
|
|
||||||
|
adder(2, 3); /* => 5 */
|
||||||
|
```
|
||||||
|
|
||||||
|
As you can see, we can apply the function in the same way.
|
||||||
|
|
||||||
|
This is useful because it means we can partially apply (or _curry_) our
|
||||||
|
functions to create other functions.
|
||||||
|
|
||||||
|
```reason
|
||||||
|
let adder = (x, y) => x + y;
|
||||||
|
let twoAdder = adder(2);
|
||||||
|
|
||||||
|
twoAdder(5); /* => 7 */
|
||||||
|
```
|
||||||
|
|
||||||
|
[source
|
||||||
|
code](https://reasonml.github.io/en/try.html?reason=DYUwLgBAhgJjICcIF4IAoAeBKFA+dAnjsvhhANQQEDcAULQFIDOAdMAPYDmas8CaAFgA0EAKxYsdWqEhgA7uwCCcRCmgr+AJkn1mbLmnlKNacZKA)
|
||||||
Reference in New Issue
Block a user