Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaredly/example-reason-codemod
https://github.com/jaredly/example-reason-codemod
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jaredly/example-reason-codemod
- Owner: jaredly
- Created: 2018-09-25T06:57:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-25T06:57:25.000Z (about 6 years ago)
- Last Synced: 2024-10-13T19:07:23.484Z (about 1 month ago)
- Language: OCaml
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Example Codemod
Here's an example of a type-driven codemod!
It finds functions that have a return type of `Belt.Result.t(int, string)`, and wraps the error payloads with `Unspecified`.
So, for the file:
```reason
open Result;let changeMe = (a, b, c) => Error("hello");
let nonCollapsible = something =>
if (something > 2) {
Result.Ok(something);
} else {
Error("bad news");
};
```It rewrites as:
```reason
open Result;let changeMe = (a, b, c) => Error("hello");
let nonCollapsible = something =>
if (something > 2) {
Result.Ok(something);
} else {
Error(Unspecified("bad news"));
};
```Note that the first `Error()` was not wrapped, because we specified that the `'ok` type had to be `int`. We could have left the `ok` type argument blank, and it would have picked that one up too.