JSFiddle - React, Tailwind, and code Playground

by dimitrs_papadimitriou

JavaScript

const right = (v) => ({
  v: v,
  map: (f) => right(f(v)),  
});

const left = (v) => ({
  v: v,
  map: () => left(v), 
});



var PromiseE = function (actions ) { 

  this.then = function (callback) {
    actions(callback,()=>{ }) 
    return this;
  }

  this.catch = function (callback) {
    actions(()=>{ }, callback) 
    return this;
 }

  this.map = function (mapping) { 
      var initialPromise  = this;
      return new PromiseE(function (resolve) {
         initialPromise.then(result => resolve(mapping(result)))
      });
  }
 
   this.cata  = function(alg){ 
    actions(callback,()=>{ }) 
     if(a)a(alg.right);
     if(b)b(alg.left ); 
    
    } 
}
 
  return new Promise(function (resolve, reject) {      setTimeout(() => {resolve(x * x); }, 1000);   });//.then(console.log).catch(x=>console.log('Error'+x)); 
  


// Promise.prototype.bind = function(func) {
//   var initialPromise = this;
//   return new Promise(function(resolve) {
//     initialPromise.then(result => func(result).then(x => resolve(x)))
//   });
// };

// Promise.prototype.map = function(mapping) {
//   var initialPromise = this;
//   return new Promise(function(resolve) {
//     initialPromise.then(result => resolve(mapping(result)))
//   });
// }
 
// const right = (v) => ({
//   v: v,
//   map: (f) => right(f(v)),  
// });

// const left = (v) => ({
//   v: v,
//   map: () => left(v), 
// });

// const Coyoneda = (  f) => ({
//   f: f,
//   map: g => Coyoneda( x => g(f(x))), 
//   lower: (x) => f(x)
// });

// var f=x=>t=>t(x*x);

// var toCont1 = f=>t=>x=>t(f(x)) 
// var toCont2 = t=>f=>x=>t(f(x)) 
// var toCont3 = x=>f=>t=>t(f(x)) 

 

// var PromiseE = (c)=>({cata:alg=>{ 
 
//  if(a)a(alg.right);
//  if(b)b(alg.left ); 

// }});

// //map:f=>PromiseE(r) .cata( PromiseE.cata({right:x=>console.log(x), left:x=>console.log('left')})   )}   );

// PromiseE((resolve,reject)=>{
  
//   reject(5)
// }) 
// .cata({
//   right:x=>console.log('righgt '+x), 
//  ...