Is this a valid monad transformer in Javascript?

前端 未结 1 588
闹比i
闹比i 2021-01-03 10:47

In order to better understand monad transformers I implemented one. Since Javascript is dynamically typed I don\'t mimic type or data constructors but declare only plain old

相关标签:
1条回答
  • 2021-01-03 11:47

    Is the cause of this problem that the way I apply chain is wrong?

    Yes. You need to pass an mf that returns an arraym, not an array like addm does. You could use

    const addmm = x => y => array.map(maybe.of)(addm(x)(y))
    arraym.chain(x => arraym.chain( addmm(x) )(arrayOfMaybes))([[10]])
    

    To help with this, you also might consider implementing lift for every monad transformer.

    0 讨论(0)
提交回复
热议问题