Questions tagged [transducer]

83 questions
2
votes
1 answer

Can clojure inspired transducers be typed with the HM type system?

I have a purely functional transducer implementation in Javascript that supports loop-fusion and short circuiting. Please note that although I am using JS it is not a requirement for understanding the question. Only the types matter. // ((a -> r)…
2
votes
4 answers

How to adapt the IReduceInit from next.jdbc to stream JSON using cheshire to a HTTP response using ring

tl;dr how to turn an IReduceInit into a lazy-seq of transformed values I have a database query which yields a reasonably large dataset for live pivoting on the client (million or two rows, 25 attributes - no problem for a modern laptop). My…
pete23
  • 2,204
  • 23
  • 28
2
votes
1 answer

Typescript type errors on Ramda Transducers & how to deal with confusing type errors on good code

Looking at the Ramda documentation for transduce, there are two examples given, each of which cause the Typescript compiler to throw a different error. Example 1: test('ex. 1', () => { const numbers = [1, 2, 3, 4] const transducer = compose( …
RichardForrester
  • 1,048
  • 11
  • 19
2
votes
2 answers

How to functional compose transforms of objects via transducers

Live code example I'm trying to learn transducers via egghead and I think I got it until we try to compose object transformation. I have an example below that doesn't work const flip = map(([k,v]) => ({[v]: k})); const double = map(([k,v]) =>…
2
votes
2 answers

Can I transduce / educe over multiple collections without concatting them

Below is a bare-bones version of what I'm doing: (eduction (map inc) (concat [1 2] [3 4])) ; -> (2 3 4 5) Is there a way to get the same eduction, without having to pay the cost of concat, which creates an intermediate lazy seq? The following would…
Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156
2
votes
1 answer

Rolling average, vb.net

I have a sensor (a Quartzonix pressure transducer, actually) that spits out data via the serial port, around 3 times a second. I'd like to set up some code to give me an average reading based on x-amount of samples. The output looks something like…
diashto
  • 37
  • 7
2
votes
0 answers

Why function reduce don't accept multiple collections like function map?

When Rich introduced transducer in clojure, the concept is base on an assumption that map can be implemented via reduce. But how we can implement (map + [1 2] [1 2]) via reduce if reduce don't accept multiple collections? To achieve this the current…
Shark
  • 93
  • 5
2
votes
1 answer

How to avoid intermediate results when performing array iterations?

When working with arrays, intermediate representations are needed regularly - particularly in connection with functional programming, in which data is often treated as immutable: const square = x => x * x; const odd = x => (x & 1) === 1; let xs =…
user5536315
2
votes
1 answer

Transduce: Why this transduce doesn't print anything

I have the following code, and I have expected it to print 1,2,3,4 on console, and return [true,true,true,true]. But it just return empty and doesn't print anything on console. The logic is: it loop for (0..3), inc every element by 1, so I got…
Daniel Wu
  • 5,853
  • 12
  • 42
  • 93
2
votes
1 answer

Remove unwanted annotation label using JAPE in GATE developer

I wanted a JAPE which on execute will return Annotation list which only sounds meaning to my requirement. Like I do not want SpaceToken, Sentence, Token, Lookup etc. implicit in my Annotation. As this Jape will be in last of Application sequence and…
Sumit Ramteke
  • 1,487
  • 1
  • 16
  • 39
2
votes
1 answer

Opportunity to use a transducer?

Using Clojure, I'm pulling some data out of a SQLite DB. It will arrive in the form of a list of maps. Here is an abbreviated sample of what the data looks like. ( {:department-id 1 :employee-firstname "Fred" :employee-lastname "Bloggs"} …
Simon Lomax
  • 8,714
  • 8
  • 42
  • 75
2
votes
1 answer

Were transducers in the Reducers library in Clojure 1.5 all along?

I heard a comment made today: "Tranducers were there all along, they came with the reducers in 1.5" Indeed - Richs's Anatomy of a Reducer blog entry, bears remarkable resemblance to the logic used in his Strange Loop Transducers talk. (Replace…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
1
vote
1 answer

Clojure Spec to parse Reducible

The doc of clojure.spec.alpha/+ says: Returns a regex op that matches one or more values matching pred. Produces a vector of matches And I can use it like this: erdos=> (s/conform (s/+ (s/cat :e #{\a \b \c})) (seq "abc")) [{:e \a} {:e \b} {:e…
erdos
  • 3,135
  • 2
  • 16
  • 27
1
vote
0 answers

Detect cyclic feeding interactions without applying XFST replace rules to lexicon

The following two XFST replace rules represent a cyclic feeding interaction, where the final result includes the original form because the first rule feeds into the second and the second feeds into the first. For example, the first rule would…
reynoldsnlp
  • 1,072
  • 1
  • 18
  • 45
1
vote
1 answer

Generate output based on first character of a word

I am trying to set up a Finite State Transducer with Helsinki Finite State Technology (HFST) for Python. I want if the first character of a word is an 'o' the output is "Positive" and if there are characters following in the same word, output empty…