TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Transducers.js: A JavaScript Library for Transformation of Data

139 pointsby jlongsterover 10 years ago

6 comments

worldsayshiover 10 years ago
The idea of declaratively describing transformations of data seems very exciting to me. I haven&#x27;t experienced anything that lives up to the excitement though.<p>I feel a bit underwhelmed by these examples. Seems a bit to imperative, an enhancement of underscore. I want the declarations of how data representations relate to each other to be separate from the &quot;how&quot; in how to transform from one format to another. Probably something inspired by lenses (1). &quot;Lenses are the XPath of _everything_.&quot; (2).<p>(1) - <a href="https://www.fpcomplete.com/school/to-infinity-and-beyond/pick-of-the-week/a-little-lens-starter-tutorial" rel="nofollow">https:&#x2F;&#x2F;www.fpcomplete.com&#x2F;school&#x2F;to-infinity-and-beyond&#x2F;pic...</a><p>(2) - <a href="https://twitter.com/steveklabnik/status/463748643141349376" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;steveklabnik&#x2F;status&#x2F;463748643141349376</a><p>edit: Relevant HN comment about using Lenses for reaching into data objects: <a href="https://news.ycombinator.com/item?id=7704504" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7704504</a>
lame_duckover 10 years ago
Just by glancing quickly over it it&#x27;s difficult to draw big conclusions but, while the concept certainly feels promising I&#x27;m not sure about API - transduce require 4 parameters and it feels like you really need to know what happens inside to make use of it (that append function feels especially off). But maybe it&#x27;s just me not being able to switch to functional way and it&#x27;s simply a matter of spending some time with it (and do some serious work with it).
评论 #8338827 未加载
评论 #8338983 未加载
ericbbover 10 years ago
Reading that article inspired me to write a little generic recursion library. The idea is that you&#x27;d write a &#x27;map&#x27; function for each recursive data structure and then generate recursive functions from non-recursive functions using &#x27;induction&#x27; and &#x27;coinduction&#x27;.<p><pre><code> &#x2F;&#x2F; induction : ((t (Fix t), Fix t -&gt; r) -&gt; t r, t r -&gt; r) -&gt; Fix t -&gt; r function induction(map, f) { &#x2F;&#x2F; g : Fix t -&gt; r function g(x) { return f(map(x.unfold(), g)); }; return g; }; &#x2F;&#x2F; coinduction : ((t s, s -&gt; Fix t) -&gt; t (Fix t), s -&gt; t s) -&gt; s -&gt; Fix t function coinduction(map, f) { &#x2F;&#x2F; g : s -&gt; Fix t function g(s) { return { unfold: function() { return map(f(s), g); } }; }; return g; }; &#x2F;&#x2F; fold : t (Fix t) -&gt; Fix t function fold(w) { return { unfold: function() { return w; } }; };</code></pre>
jzelinskieover 10 years ago
For some reason (maybe environmental factors), I understood this article much better than Rich Hickeys initial post. However, I suppose I should now go back and re-read it.<p>Thanks for the great library and explanation.
评论 #8338606 未加载
cnpover 10 years ago
Practical examples go a long, long way when showcasing libraries such as this.
mcavover 10 years ago
I think the name &quot;transducers&quot; is a little unfortunate only in that it sounds very foreign to most coders, leading the concept to potentially be ignored. Don&#x27;t let the name &quot;transducers&quot; or the relation to Clojure scare you off; you don&#x27;t have to know either thing to understand how transducers can be useful.
评论 #8337869 未加载
评论 #8337897 未加载
评论 #8337907 未加载
评论 #8338585 未加载
评论 #8339360 未加载
评论 #8338595 未加载