Skip to content

Instantly share code, notes, and snippets.

View AkshayGuptaK's full-sized avatar

Akshay Gupta AkshayGuptaK

  • Bit By Bit
  • Bangalore
View GitHub Profile
@AkshayGuptaK
AkshayGuptaK / list.js
Created August 9, 2020 13:42
List Monad in JS
function List(lst) {
return {
of: lst,
fmap: (fn) => List(lst.map(fn)),
join: () => List(lst.reduce((acc, l) => acc.concat(l), [])),
bind: function (fn) {
return this.fmap(fn).join();
},
};
}