Skip to content

Instantly share code, notes, and snippets.

@humanhighway
Created February 7, 2021 09:40
Show Gist options
  • Save humanhighway/6398398a99edfc9dd111dea03e490c1f to your computer and use it in GitHub Desktop.
Save humanhighway/6398398a99edfc9dd111dea03e490c1f to your computer and use it in GitHub Desktop.

Revisions

  1. humanhighway created this gist Feb 7, 2021.
    11 changes: 11 additions & 0 deletions box-example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    const Box = (x) => ({
    map: f => Box(f(x)), // always return Box type.
    fold: (f) => f(x), // unwarp value
    })

    const result= Box(10)
    .map((x) => x * 2)
    .map((x) => x + 10)
    .fold(x => x);

    console.log(result);