Transducers Come To Clojure and Javascript |
Written by Alex Denham |
Monday, 22 September 2014 |
Two new libraries have been released adding transducers to Clojure and to JavaScript
A transducer gives you a way to work on a collection of values to produce either a new value or a collection of new values. The name is derived by combining transform and reduce, and a transducer (used in the context of Clojure and JavaScipt) is a reducing function transformer. A transducer transforms the data to produce some value from another, and reduces it in the sense of combining the values of a data structure to produce a new one. The reduce function is the base transformation; any other transformation can be expressed in terms of it (map, filter, etc). In a blog post describing what transducers do, Rich Hickey says transducers provide a better way of dealing with situations where you might need to create bespoke replicas of map, filter and mapcat. Hickey says that a reducing function is just the kind of function you'd pass to reduce - it takes a result so far and a new input and returns the next result-so-far. In the context of transducers it's best to think about this as:
and that a transducer is a function that takes one reducing function and returns another:
Hickey explains that the primary power of transducers comes from their fundamental decoupling and that they they don't care (or know about):
He explains these ideas in more detail in Anatomy of a Reducer on the Clojure blog. The transducer support Hickey has added to Clojure on Github is being described as alpha and subject to change. Meanwhile, inspired by the power of transducers, Mozilla webdev James Long has written his own version for JavaScript. On his blog describing the new library, Long describes transducers as mind-blowing, and says transducers.js lets you build transformations of data and apply it to any data type you could imagine. It is an aproach worth finding out about if you need a new way to work with data.
More InformationTransducer support in Clojure (Github) Transducers.js: A JavaScript Library for Transformation of Data Related ArticlesIntel Announces Beta Data Platform To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
Comments
or email your comment to: comments@i-programmer.info
|
Last Updated ( Monday, 22 September 2014 ) |