Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryloric/bs-list
BuckleScript bindings for funkia/list
https://github.com/ryloric/bs-list
bucklescript-bindings ocaml reasonml
Last synced: 29 days ago
JSON representation
BuckleScript bindings for funkia/list
- Host: GitHub
- URL: https://github.com/ryloric/bs-list
- Owner: ryloric
- Created: 2019-04-05T11:43:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-05T12:25:46.000Z (almost 6 years ago)
- Last Synced: 2024-10-11T13:37:16.366Z (3 months ago)
- Topics: bucklescript-bindings, ocaml, reasonml
- Language: OCaml
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bs-list
Bucklescript bindings to [funkia/list](https://github.com/funkia/list)
Currently compiles to function-application-style in javascript.
## Install
```
npm i -s bs-list
```
add `bs-list` to `bs-dependencies` in `bsconfig.json`## Sample Usage
``` OCaml
let () =
let open Flist in
lst [|1;2;3|]
|> map ~f:(fun x -> x + 1)
|> adjust 2 ~f:(fun x -> x * 2)
|> foldl ~f:(fun x acc -> x * acc) 0
|> Js.log
```Please look at `list`'s [docs](https://github.com/funkia/list/README.md) for all the available functions.
## Why
In an ideal scenario, we should be able to write code using OCaml's `'a list` type in the usual way,using recursion and pattern matching, and then make `bsc` compile it down to whatever representation
we want `'a list` to have in Javascript. In a way we are mapping idiomatic OCaml's `'a list` api to whatever is our preffered/efficient js representation.Unfortunately, `bsc` doesn't let us do that at the moment, it has it's own representation of `'a list` which is a two element array of `[head, tail]` where `tail` is another array, with empty list being `0`. It's not efficient, but you get to use pattern matching. The other option is to use Js.Array, but the api is lacking, doesn't have any of the nice things `'a list` has.
Using `funkia/list` is a compromise, it has a pretty comprehensive api like `'a list` but can't use pattern matching, is very efficient like `Js.Array` but has a nicer api.