OverZealous/lazypipe

question: comparison to multipipe

Closed this issue · 3 comments

i'm kind of a novice to gulp and indeed node, and i'm going thru what is probably a typical exercise of trying to 'dry' up a gulp-file.

i have come across lazypipe and multipipe and they seem to have similar capabilities in terms of composition of streams, but i don't think i understand the nuance of their differences (particularly when used in conjunction with gulp).

perhaps something around immutability?

anyone familiar enough with both packages to shed some light for me?

regards,
tony.

I'm not sure this is the right place to ask this.

Lazypipe is specifically designed to make it easy to create clean, reusable pipes. Multipipe would need to be encapsulated within a function to get the same result. To compare:

// using lazypipe
var pipe1 = lazypipe()
            .pipe(foo) // notice, the stream handler has not been created [ foo vs foo() ]
            .pipe(bar, barArg)
            .pipe(baz);

// using multipipe
function pipe2() {
    return multipipe(
            foo(),
            bar(barArg),
            baz()
        );
}

Both would be used in the same manner:

gulp.src(...).pipe(pipe1());
// or
gulp.src(...).pipe(pipe2());

They have 90% the same functionality, although the function method allows you to create a stream with dynamic components, while lazypipes are always static.


Lazypipe has one potential advantage: when piping one lazypipe into another, it internally streamlines the result so you have less wrapper functions. This probably doesn't have a meaningful effect on the process.


Lazypipe's immutability and dynamic creation of the pipeline is why you need to wrap multipipe in a function. If you use it like this:

var pipe3 = multipipe(foo(), bar(barArg), baz());

Then your pipe is most likely not reusable, because you'll end up creating a tree of pipes, where all the sources go into all the destinations.


Finally, lazypipe internally uses stream-combiner rather than multipipe. While multipipe handles newer streams better, I've had issues with it silently not passing files through, and I've not replaced ES with it for that reason.

wow, thanks phil, that was super helpful!

and you're right, i should have posted this to stack-overflow where i would have up-voted your response 👍

Ha! Of course, they'd have closed it on SO as inappropriate.

Good luck with your gulp script!