id | keywords | name | summary | category | ||
---|---|---|---|---|---|---|
uncurry-decorator |
|
@uncurry |
This is the `@uncurry` decorator. |
decorators |
The @uncurry
decorator can be used to mark any callback argument within an external function as an uncurried function without the need for any explicit uncurried function syntax ((.) => { ... })
.
In the following example we are binding to a function map(arr, callback)
and use the @uncurry
annotation to make sure that callback
is always treated as an uncurried function:
<CodeTab labels={["ReScript", "JS Output"]}>
@bs.send
external map: (array<'a>, @uncurry ('a => 'b)) => array<'b> = "map"
let result = map([1, 2, 3], x => x + 1)
var result = [1, 2, 3].map(function (x) {
return (x + 1) | 0
})
As we can see, we defined a regular function ('a) => 'b
instead of (. 'a) => 'b
, but still have all the guarantees. Please note that the compiler does a lot of optimizations, so the example above will compile to the same code even without the @uncurry
decorator. Adding the decorator (or using the (.) =>
syntax) makes the output 100% predictable though.