lautis/piperator

Improvement suggestion

Closed this issue · 4 comments

Nice work, mate!

This seems like a useful lib/approach many people may start using. After reading the article "Streaming Data with Ruby Enumerators", I have a suggestion of an improvement. Do you think it will make it clearer and simpler to follow if you move the argument at the beginning of a pipeline?

For example:

Piperator::Pipeline
  .pipe(HTTPFetch)
  .pipe(GZipDecoder)
  .pipe(length)
  .call('http://ftp.gnu.org/gnu/gzip/gzip-1.2.4.tar.gz')

Becoming:

Piperator::Pipeline('http://ftp.gnu.org/gnu/gzip/gzip-1.2.4.tar.gz')
  .pipe(HTTPFetch)
  .pipe(GZipDecoder)
  .pipe(length)
  .call

p.s. I've added the piperator to "Awesome Ruby" - https://ruby.libhunt.com/project/piperator

ianks commented

Hey @StanBright, I'm not a contributor (yet 😉) but I personally feel this will make it harder to understand. For example, imagine if you pass the pipeline as a argument to another class. At this point, it becomes easy to forget what the pipeline was instantiated with. Also, as a bigger concern, the pipelines become less reusable as they are coupled to the initial argument.

@ianks I see you point, and it totally makes sense. Yet, coming from Elixir, the initial argument is always in the beginning. That makes it easier to follow the data flow. Maybe, that could be an option...

The pipeline from example can be written as

Piperator::Pipeline
  .pipe('http://ftp.gnu.org/gnu/gzip/gzip-1.2.4.tar.gz')
  .pipe(HTTPFetch)
  .pipe(GZipDecoder)
  .pipe(length)
  .call

The issues @ianks mentioned about composability are the reason why I went with URL as last parameter.

To get the syntax @StanBright suggested, there could be a method def Piperator as an alias for Piperator.pipe. At least as long as auto-wrapping (#2) isn't removed.

@lautis thanks for the response. I think .pipe('http://ftp.gnu.org/gnu/gzip/gzip-1.2.4.tar.gz') at the beginning is perfect. Cheers!