JSFiddle - React, Tailwind, and code Playground

by fresheyeball

CoffeeScript

class Tuple
  constructor : (@__fst, @__snd) ->
  _fmap : (f) -> new Tuple (f @__fst), (f @__snd)
  _fst  : -> @__fst
  _snd : -> @__snd
  _ap   : (t) -> new Tuple ((fst t) @__fst), ((snd t) @__snd)
  _show : -> "Tuple(#{@__fst}, #{@__snd})"
    
Object::ap     = (a) -> a._ap @
Function::fmap = (a) -> a._fmap @
fst  = (t) -> t._fst()
snd  = (t) -> t._snd()
show = (a) -> a._show()
add  = (x) -> (y) -> x + y

# let t = (1, 2)
t = new Tuple 1, 2

# let tt = (+5) <$> t
tt = (add 5).fmap(t)

# let ttt = (+) <$> t <*> tt
ttt = add.fmap(t).ap(tt)

# show . trace $ ttt
alert show ttt