The pipeline in OCaml
|> feeds the left value forward; data reads in flow order.
(* |> feeds the left value forward: data reads in flow order. *)
let counts = [12; 5; 31; 8; 19]
let busy_pools =
counts
|> List.filter (fun c -> c > 10)
|> List.length
let () =
Printf.printf "Pools above ten animals: %d\n" busy_pools;
(* The pipeless version reads inside out. *)
Printf.printf "Total: %d\n" (List.fold_left ( + ) 0 counts);
counts |> List.map string_of_int |> String.concat ", "
|> print_endline
How it works
counts |> List.filter ... |> List.lengthreads as a sentence.- The pipeless version nests inside out.
- Pipelines end anywhere a function fits, even
print_endline.
Keywords and builtins used here
funlet
The run, in numbers
- Lines
- 14
- Characters to type
- 415
- Tokens
- 90
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 83 seconds.
Step 2 of 4 in Functions, step 5 of 29 in Language basics.