Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transducers.drop(n) not working as expected #58

Open
threepointone opened this issue Apr 29, 2015 · 5 comments
Open

transducers.drop(n) not working as expected #58

threepointone opened this issue Apr 29, 2015 · 5 comments

Comments

@threepointone
Copy link

import csp, {go, chan} from 'js-csp';
let {fromColl, into, pipeline} = csp.operations;
import xd from 'transducers.js';

// the regular transducer works fine
console.log(xd.seq([1, 2, 3, 4, 5], xd.drop(2)))
// outputs [3, 4, 5]

// but not when used with a channel
go(function*(){
  var c = chan();
  pipeline(c, xd.drop(2), fromColl([1, 2, 3, 4, 5]));
  var res = yield into([], c);  
  console.log(res);
  // expected - [3, 4, 5]
  // actual - []
})
@threepointone
Copy link
Author

not sure if related, but dedupe() doesn't work either.

console.log(xd.seq([1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7], xd.dedupe()))
// as expected - [ 1, 2, 3, 4, 5, 6, 7 ]

go(function*(){
  var c = chan(7);
  pipeline(c, xd.dedupe(), fromColl([1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7]));
  var res = yield into([], c);  
  console.log(res);
  // - expected - [ 1, 2, 3, 4, 5, 6, 7 ]
  // - actual - [ 1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5, 5, 6, 7 ]
})

@ubolonton
Copy link
Contributor

Seems to be a pipeline bug. Attaching transducers directly to channels works.
I'm checking it.

@ubolonton
Copy link
Contributor

Actually that's how pipeline is "supposed" to work: applying the transformation to individual items.

In Clojure it's useful for parallelization of non-stateful transformations. In single-threaded js runtimes it's actually quite useless.

@ubolonton
Copy link
Contributor

We need to do the following

  • Update the doc to make it clear that pipelineAsync is for parallelism.
  • Remove pipeline or fix its doc.
  • Maybe augment pipe for the use case of "connecting 2 existing channels via a transducer" (if the code is in control of either channel, it can just attach the transducer when creating the channel).

@threepointone
Copy link
Author

ah, I see what you're saying. I worked around it by passing a transducer to the created channel. thanks much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants