Questions tagged [transducer]
83 questions
4
votes
1 answer
Is it possible to implement scan as a transducer
I notice that scan is missing from the various transducer libraries that I looked at (e.g transducers-js). Is it impossible to implement or am I missing something?

Peter Hall
- 53,120
- 14
- 139
- 204
4
votes
2 answers
How can one simulate nondeterministic finite transducers?
A nondeterministic automaton can be simulated easily on an input string by just keeping track of the states the automaton is in, and how far in the input string it has gotten. But how can a nondeterministic transducer (a transducer, of course, can…

oskarkv
- 2,329
- 2
- 21
- 29
3
votes
1 answer
Why does the result of a mapping transducer include greater-than-2 arities?
The question is in the title. Below I copy the transducer-part of the source of map:
([f]
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(rf result (f input)))
([result input & inputs] ;why?
…

peter pun
- 384
- 1
- 8
3
votes
2 answers
JavaScript `reduce` performance
I've spent some time recently plying around with transducers (tool in functional programming meant to improve performance without losing readability/flexibility of code) and when I came to testing their actual speed, I got some quite disappointing…

Michał Kaczanowicz
- 587
- 6
- 14
3
votes
1 answer
Why doesn't my transducer work anymore when abstracting from reducing/composing?
I am stuck with my short circuiting and stack safe transducer implementation:
const loop = f => {
let acc = f();
while (acc && acc.type === tailRec)
acc = f(...acc.args);
return acc;
};
const tailRec = (...args) =>
…
user10675354
3
votes
2 answers
Transducer flatten and uniq
I'm wondering if there is a way by using a transducer for flattening a list and filter on unique values?
By chaining, it is very easy:
import {uniq, flattenDeep} from 'lodash';|
const arr = [1, 2, [2, 3], [1, [4,…

Guillaume Cisco
- 2,859
- 24
- 25
3
votes
1 answer
Order of Execution of Composed Function
I have been reading up on transducers and playing around trying to grasp the concept. I now understand them a bit, but during my fiddling, I came across something very peculiar that has me dumbfounded. I'm hoping someone can explain what I'm…

user3467104
- 55
- 6
3
votes
2 answers
Pmap inside a transducer in Clojure
I would like to use pmap within a transducer, if I write my code using regular map, it works fine. However if I use pmap I get an arity exception. Is it possible to achieve this in clojure or am I doing something wrong?
If it were to be impossible,…

Joaquin
- 121
- 9
3
votes
2 answers
How to visualize Pyfst transducers via dot files
I am learning how to create transducers with Pyfst and I am trying to visualize the ones I create. The ultimate goal is to be able to write the transducers to dot files and see them in Graphviz.
I took a sample code to see how to visualize the…

nanachan
- 1,051
- 1
- 15
- 26
3
votes
2 answers
What does sequence do with a transducer?
Two related questions about sequence:
Given a transducer, e.g. (def xf (comp (filter odd?) (map inc))),
What's the relationship between (into [] xf (range 10)) or (into () xf (range 10)), and (sequence xf (range 10))? Is it just that there's no…

Mars
- 8,689
- 2
- 42
- 70
3
votes
1 answer
What's the difference between these functions implemented with currying and transducers?
Taking the three functions below, implemented in Haskell and Clojure respectively:
f :: [Int] -> Int
f = foldl1 (+) . map (*7) . filter even
(defn f [coll]
((comp
(partial reduce +)
(partial map #(* 7 %)
(partial filter even?))…

Fuad Saud
- 3,086
- 1
- 15
- 16
3
votes
1 answer
Clojure - How does this work when `comp` goes from right to left?
The documentation for comp states that it starts with the rightmost function, applies the arguments to it, then gives the result to the next function and so on. Hence here the numbers are added first then str is applied to the integer 16:
((comp str…

Chris Murphy
- 6,411
- 1
- 24
- 42
3
votes
2 answers
Representing a Transducer Systems in sml
I need help writing code such that:
Given two functions, say f1 and f2 and an initial input i1 for f1, I will feed i1 to f1 and whatever ouptput it returns, I will feed to f2 and whatever f2 returns I will feed to f1 and so on...
Thus it will look…

Sarah cartenz
- 1,313
- 2
- 14
- 37
3
votes
3 answers
Value restriction woes
I was experimenting with an implementation of Clojure Transducers in F#, and quickly hit the dreaded Value Restriction error.
The whole point of Transducers is to be composable. This is some sample code:
type Reducer<'a,'b,'c> = ('a -> 'b -> 'a) ->…

Robert Jeppesen
- 7,837
- 3
- 35
- 50
2
votes
1 answer
Finite-state transducer that computes the relation
From http://www.cse.ohio-state.edu/~gurari/theory-bk/theory-bk-twoli1.html#30007-23021r2.2.4:
Let M =
be the deterministic finite-state transducer whose transition diagram is given in Figure 2.E.2. For each of the following…

oogly
- 115
- 1
- 8