tag:blogger.com,1999:blog-22587889.post2712980585988306755..comments2024-02-11T13:21:47.930+05:30Comments on Ruminations of a Programmer: Endo is the new fluent APIAnonymoushttp://www.blogger.com/profile/01613713587074301135noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-22587889.post-6693034460544908622013-08-07T08:14:12.185+05:302013-08-07T08:14:12.185+05:30This is cool!This is cool!Vernonhttp://topconvertiblecarseatreviews.net/noreply@blogger.comtag:blogger.com,1999:blog-22587889.post-4029956415312746892013-06-04T14:35:42.007+05:302013-06-04T14:35:42.007+05:30We can generalise Endo[A] to Kleisli[Id, A, A] (wh...We can generalise Endo[A] to Kleisli[Id, A, A] (where Id is the identity monad). (In fact, we can generalise it further to arbitrary categories, but Kleisli alone provides a lot of power.)<br /><br />For Kleisli[F, A, A] when F is a monad, there is a monoid where mappend is kleisli composition, and mzero is the kleisli arrow corresponding to the function (a: A) => a.point[F]. When F is Id, this gives us the same behaviour as the monoid for Endo[A].<br /><br />But we can now choose F to be any monad, allowing us to add error handling, reader, writer, state etc. to the computation, while retaining the fluent-like simplicity of monoidal addition.<br /><br />As is often the case in functional programming, generalising the concept reveals something more powerful; really, the OO version of "fluent APIs" are quite restricted and not all that expressive compared to simple combinators like |+|.<br /><br />(Apologies if this is pre-empting a future post!)Anonymousnoreply@blogger.com