Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 1.32 KB

decorator_uncurry.mdx

File metadata and controls

36 lines (25 loc) · 1.32 KB
id keywords name summary category
uncurry-decorator
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 ((.) => { ... }).

Example

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.

References