We see three varied examples of the where natural transformations come in handy.
Constright = x = =({chain:f=f (x), Ap:other=Other.map (x), Traverse: (OF, F)=f (x). Map (right), Map:f=Right (f (x)), fold: (f, g)=g (x), Concat:o= = O.fold (_ + = Right (x), y = =Right (X.concat (y)), toString: ()=' Right (${x}) ');Constleft = x =({chain:f=Left (x), Ap:other=Left (x), Traverse: (OF, F)=of (Left (x)), Map:f=Left (x), fold: (f, g)=f (x), Concat:o= = O.fold (_ = = Left (x), y = =o), toString: ()=' Left (${x}) ');Constfromnullable = x = x = =NULL?Right (x): Left (NULL);ConstTask = require ('Data.task');Const{List} = require ('Immutable-ext');Constfake = id = =({ID, Name:'User1', Best_friend_id:id+1 });ConstDb =({find:id=NewTask ((REJ, res) = ={res (ID>2? Right (fake (ID)): Left ('Not found')) })});ConstEithertotask = e =E.fold (task.rejected, task.of);//Right (x)--Task (user)Constres = Db.find (3)//Task (right (user)). Chain (Eithertotask)//Task (user). Chain (user =Db.find (user.best_friend_id))//Task (right (user)). Chain (Eithertotask)//Task (user). Fork (E =Console.error (e), R=Console.log (R));
[Compose] 21. Apply Natural transformations in everyday work