https://github.com/jaredly/get_in_ppx
https://github.com/jaredly/get_in_ppx
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/jaredly/get_in_ppx
- Owner: jaredly
- Created: 2018-10-31T12:53:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-18T19:57:41.000Z (over 6 years ago)
- Last Synced: 2025-04-22T18:55:44.360Z (about 1 year ago)
- Language: Reason
- Size: 2.01 MB
- Stars: 40
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# get_in ppx
An exploration of the ["safe call operators" pull-request](https://github.com/facebook/reason/pull/2142), implemented as a ppx.
## Installation
`npm i get_in_ppx`
bsconfig.json
```
"ppx-flags": ["get_in_ppx/ppx"]
```
## Operators
This ppx includes two operators, that are valid within the `[%get_in ]` form.
- `#??` is to be used when *both sides* are optional. E.g. the object on the left is optional, and the attribute you're getting out is also optional. e.g. `option({. "attr": option(int)})`
- `#?` is to be used when *only the object* is optional, but the attribute you're getting out is not. e.g. `option({. "attr": int})`
## Usage
```
/* some data with optional attributes in javascript objects (e.g. from graphql) */
let one = Some({"two": Some({"three": 4})});
let x: option(int) = [%get_in one#??two#?three];
```