No description
Find a file
2022-12-17 02:14:52 +00:00
src Fix regression on lambda composition, and thus on composition of compositions 2022-12-17 02:14:19 +00:00
tests Add tests for lambdas, identified regression regarding them and composing composed procs 2022-12-17 01:59:46 +00:00
.gitignore Add "generic" return type for << based on the one for the left operand 2022-12-07 02:14:56 +00:00
compose.nimble Bump patch version 2022-12-17 02:14:52 +00:00
LICENSE Add MIT license, add description 2022-11-30 03:43:33 +00:00
packages.json Add packaging information for maintainer 2022-12-08 01:05:42 +00:00
README.md Update README with new to-dos and example for multiple argument 2022-12-16 01:51:00 +00:00

Nim-compose

Composition operators for Nim.

Usage

import compose

func add20(x: int): int = x + 20
func mul3(x: int): int = x * 3

let
  add40 = add20 << add20
  mul9 = mul3 << mul3
  add80 = compose(add40, add20, add20)
  add20_then_mul3 = mul3 << add20
  mul3_then_add20 = mul3 >> add20

10.add40.echo
10.mul9.echo
10.add80.echo

10.add20_then_mul3.echo
10.mul3_then_add20.echo

func multiAdd30(x,y,z: float): float = x + y + z + 30.0
func div2(x: float): float = x / 2.0

# Multiple argument procs must be on the inner operand
let sum30over2 = multiAdd30 >> div2
sum30over2(3,4,5)

# Make sure that the return type matches the parameter type
func add50(x: float): float = x + 50.0
func gt200(x: float): bool = x > 200.0

let gt150 = add50 >> gt200

140.gt150.echo
160.gt150.echo

To-do

  • Support overloaded procs
  • Support default parameter values
  • Some mechanism for allowing multi-argument procs in outer operand. Maybe currying, maybe with placeholder