Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Func Category id commutativity">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Func Cateogry id commutativity</title>
</head>
<body>
</body>
</html>
 
class Func {
  constructor(f) {
    // this.run = f
    this.run = x => f(x)
    
    // this :: Cat (x ↣ y)
    // Cat (y ↣ z) -> Cat (x ↣ z)
    this.pipe = g => new Func(x => g.run(this.run(x)))
    
    // utility function that pipes Func to a normal function
    // this :: Cat (x ↣ y)
    // (y -> z) -> Cat (x ↣ z)
    this.pipeTo = g => new Func(x => g(this.run(x)))
  }
}
// Cat (x ↣ x)
Func.id = new Func(x => x)
// usge example:
const a = Func.id.pipe(new Func(x => x * 2)).run(10) 
const b = new Func(x => x * 2).pipe(Func.id).run(10) 
console.log(`id ⋙ cat : ${a}`)
console.log(`cat ⋙ id : ${b}`)
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
homampro
0viewers