Questions tagged [transducer]

83 questions
8
votes
2 answers

What is the 'parallel' concept in Rich Hickey's transducers Strange Loop talk?

In the Strange Loop presentation on Transducers Rich Hickey mentions at a concept in a table called 'parallel'. You can easily see examples of seqs and into and channels using transducers. Now you can work out that Observables are talking about…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
7
votes
1 answer

Whatever happened to `Observable.transduce` in RxJS v5+?

RxJS v4 used to have an Observable.transduce method which took a transducer. This allowed the use of library-independent transducer operators which had major performance benefits in the…
Kevin Ghadyani
  • 6,829
  • 6
  • 44
  • 62
7
votes
1 answer

Are Clojure transducers eager?

In this blog entry, "CSP and transducers in JavaScript", the author states: First, we have to realise that many array (or other collection) operations like map, filter and reverse can be defined in terms of a reduce. So then we see a number of…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
6
votes
0 answers

Transducers: What should the completion arity do if the nested step arity has returned reduced?

A stateful transducer is expected to flush its state by calling the "step" arity (i.e. [([result input] ) ) as many times as needed, before calling the "complete" arity (i.e. ([result] )). My question is how early termination (with reduced) is to be…
drRobertz
  • 3,490
  • 1
  • 12
  • 23
6
votes
1 answer

Understanding Clojure Transducer Performance

At a high level I understood that using a transducer does not create any intermediate data structures whereas a long chain of operations via ->> does and thus the transducer method is more performant. This is proven out as true in one of my examples…
burbma
  • 63
  • 1
  • 3
6
votes
1 answer

Why is my transducer function slower than using ->> operator?

While solving problem from Hackkerank (https://www.hackerrank.com/challenges/string-compression/problem) I've written 2 implementations with and without transducers. I was expecting the transducer implementation to be faster, than the function…
denis631
  • 1,765
  • 3
  • 17
  • 38
6
votes
1 answer

In Clojure, how can I do a performant version of `frequencies` with transducers?

(Question credit: Fernando Abrao.) I hear about the performance benefits of transducers in Clojure, but I'm not sure how to use them. Say I have a qos/device-qos-range function that returns sequence of maps, some of which contain a decimal…
Jeff Terrell Ph.D.
  • 2,563
  • 26
  • 39
6
votes
1 answer

Using Clojure Tranducers to parse big files: OutOfMemory Error

I want to parse a big json file (3GB) and return a hash-map for each line in this file. My intuition was to use a transducer to process the file line-by-line and construct a vector with some selected fields (> 5% of bytes in the file). However, the…
user5239066
6
votes
1 answer

Transducers in Haskell and the monomorphism restriction

I implemented transducers in Haskell as follows: {-# LANGUAGE RankNTypes #-} import Prelude hiding (foldr) import Data.Foldable type Reducer b a = a -> b -> b type Transducer a b = forall t. Reducer t b -> Reducer t a class Foldable c =>…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
5
votes
2 answers

eduction vs transducer composition

Whats the difference between: (transduce (comp fn-1 fn-2 fn-3) conj vector-collection) and (eduction fn-1 fn-2 fn-3 vector-collection) I've read the eduction docs but didn't understand the purpose of the eduction.
sumek
  • 26,495
  • 13
  • 56
  • 75
4
votes
2 answers

Why does compose apply left to right with transducers?

Example code: // Compose functionality const compose = (...fns) => { return args => { return fns.reduceRight((arg, fn) => fn(arg), args); } }; // List of transformation and predicate functions const add1 = x => x + 1; const…
FNMT8L9IN82
  • 483
  • 1
  • 9
  • 22
4
votes
1 answer

Difference between Transducer and NFA

Can someone tell me how a Transducer differs from a NFA?
samsamara
  • 4,630
  • 7
  • 36
  • 66
4
votes
2 answers

Is there a reducing function in Clojure that performs the equivalent of `first`?

I'm often writing code of the form (->> init (map ...) (filter ...) (first)) When converting this into code that uses transducers I'll end up with something like (transduce (comp (map ...) (filter ...)) (completing #(reduced %2)) nil…
Sebastian Oberhoff
  • 1,271
  • 1
  • 10
  • 16
4
votes
1 answer

What does completing function do in Clojure?

I've came across completing function on clojuredocs but there is no doc at the moment. Could you provide some examples?
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76
4
votes
1 answer

Clojure reduce transducer

I am looking for a simple example of transducers with a reducing function. I was hoping that the following would return a transducing function, since (filter odd?) works that way : (def sum (reduce +)) clojure.lang.ArityException: Wrong number of…
nha
  • 17,623
  • 13
  • 87
  • 133