Questions tagged [transducer]

83 questions
116
votes
12 answers

Can someone explain Clojure Transducers to me in Simple terms?

I have tried reading up on this but I still don't understand the value of them or what they replace. And do they make my code shorter, more understandable or what? Update Alot of people posted answers, but it would be nice to see examples of with…
yazz.com
  • 57,320
  • 66
  • 234
  • 385
59
votes
4 answers

What is a finite state transducer?

Can someone please tell me what a finite state transducer is? I have read the Wikipedia article and don't understand a thing.
user581734
  • 1,219
  • 3
  • 15
  • 24
36
votes
1 answer

How is a transducer different from a partially applied function?

After reading this article on Clojure (http://blog.podsnap.com/ducers2.html) introducing transducers, I'm confused on what a transducer is. Is a partially applied map in Haskell, such as map (+1) a transducer? At first I thought this was a Clojure…
Ramith Jayatilleka
  • 2,132
  • 16
  • 25
17
votes
6 answers

How to parse a DOT file in Python

I have a transducer saved in the form of a DOT file. I can see a graphical representation of the graphs using gvedit, but what if I want to convert the DOT file to an executable transducer, so that I can test the transducer and see what strings it…
Morteza R
  • 2,229
  • 4
  • 20
  • 31
15
votes
2 answers

Are Clojure transducers the same concept as intermediate operations on streams in Java?

As I was learning about transducers in Clojure it suddenly struck me what they reminded me of: Java 8 streams! Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and…
glts
  • 21,808
  • 12
  • 73
  • 94
14
votes
1 answer

Finite State Transducers in Haskell?

I've been wondering if there is a way to define and work with finite state transducers in Haskell in an idiomatic way. You can approach FSTs as generators (it generates an output of type {x1,x2}), or as recognizers (given an input of type {x1,x2} it…
gonzaw
  • 771
  • 4
  • 17
13
votes
1 answer

Is my understanding of transducers correct?

Let's start with a definition: A transducer is a function that takes a reducer function and returns a reducer function. A reducer is a binary function that takes an accumulator and a value and returns an accumulator. A reducer can be executed with a…
marzelin
  • 10,790
  • 2
  • 30
  • 49
13
votes
1 answer

Clojure transducers behavior

With new clojure 1.7 I decided to understand where I can use transducers. I understand what benefit they can give, but I can't find normal examples of writing custom transducers with explanation. Ok, I tried to test what is happening. I opened the…
JustAnotherCurious
  • 2,208
  • 15
  • 32
11
votes
1 answer

What is a stateful transducer?

In the Clojure Core documentation for the 1.7 release - the following functions dedupe disj! dissoc! filter keep map random-sample remove replace take-while Have the following text in their API description Returns a transducer when no collection…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
11
votes
1 answer

General Finite State Machine (Transducer) in Scala

What is the general way to implement a finite state machine (or finite state transducer) in Scala? I often find myself in need for state machine implementation. My typical implementation looks like object TypicalFSM { // actually — finite state…
Arseniy Zhizhelev
  • 2,381
  • 17
  • 21
9
votes
1 answer

Transducer's init not called

I am writing a custom transducer as an exercise, but I am surprised to see that its 0-arity init function is not called. Why? Is it related to which aggregation function I am using? If yes, which ones would call the init function and why others are…
Vincent Cantin
  • 16,192
  • 2
  • 35
  • 57
9
votes
1 answer

How to create a channel from another with transducers?

I want to create a channel of clojure.core.async from another one that just filters specific messages. Therefore I found a function called filter<. => (def c1 (chan)) => (def c2 (filter< even? c1)) => (put! c1 1) => (put! c1 2) => (
sschmeck
  • 7,233
  • 4
  • 40
  • 67
9
votes
2 answers

What are the similarities and differences between Scala Transducers and Clojure Transducers?

Paul Chiusano and Rúnar Óli have written a fantastic book Functional programming in Scala. In it they mention a little-referenced concept in the Scala community - Transducers. In the Clojure Community - Transducers get a little more press. My…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
8
votes
2 answers

Implementing Clojure conditional/branching transducer

I'm trying to make a conditional transducer in Clojure as follows: (defn if-xf "Takes a predicate and two transducers. Returns a new transducer that routes the input to one of the transducers depending on the result of the predicate." …
dsg
  • 12,924
  • 21
  • 67
  • 111
8
votes
2 answers

Could core.async have implemented its functions in terms of sequences?

Rich Hickey's Strange Loop transducers presentation tells us that there are two implementations of map in Clojure 1.6, one for sequences in clojure.core and one for channels in core.async. Now we know that in 1.7 we have transducers, for which a…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
1
2 3 4 5 6