Skip to content

IwanKaramazow/PipeFirst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipe First ppx Build Status

Pipe first as a syntax transform. Transforms expressions containing the |. (Ocaml) or -> (Reason) operator. Pipes the left side as first argument of the right side.

Reason

/* validateAge(getAge(parseData(person))) */
person
->parseData
->getAge
->validateAge;

/* Some(preprocess(name)); */
name->preprocess->Some;

/* f(a, ~b, ~c) */
a->f(~b, ~c)

Ocaml

(* validateAge (getAge (parseData person)) *)
person
|. parseData
|. getAge
|. validateAge

(* Some(preprocess name) *)
name |. preprocess |. Some;

(*f a ~b ~c *)
a |. f ~b ~c

Usage with Dune

dune file

(executable
  (name hello_world)
  (preprocess  (pps ppx_pipe_first))

Reason: implementation of the hello_world.re file

let () =
  1000
  ->string_of_int
  ->print_endline;

Ocaml: implementation of the hello_world.ml file

let () =
  1000
  |. string_of_int
  |. print_endline

Developing:

npm install -g esy
git clone <this-repo>
esy install
esy build

Running Tests:

esy test

About

Fast pipe, pipe first as a syntax transform

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages