question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pipe operator does not work with v6 as before v5

See original GitHub issue

RxJS version: 6.0.0-beta.0

Code to reproduce:

import { from } from 'rxjs';
import { concat } from 'rxjs';
import { delay } from 'rxjs/operators';

let $from1 = from([1, 2]);
$from1
    .pipe(
        delay(2000),
        concat(from([3, 4])),
        delay(2000)
    ).subscribe(v => console.log(`$from1-delay-concat: ${v}`));

Expected behavior: it should run without errors as in v5.5.6

Actual behavior:

/rxjs/node_modules/rxjs/internal/util/pipe.js:22
        return fns.reduce(function (prev, fn) { return fn(prev); }, input);
                                                       ^

TypeError: fn is not a function
    at /rxjs/node_modules/rxjs/internal/util/pipe.js:22:56
    at Array.reduce (<anonymous>)
    at piped (/rxjs/node_modules/rxjs/internal/util/pipe.js:22:20)
    at Observable.pipe (rxjs/node_modules/rxjs/internal/Observable.js:252:48)
    at Object.<anonymous> (rxjs/lib/index.js:18:25)
    at Module._compile (module.js:657:14)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

Additional information: Its not possible to investigate the issue/problem by my self because i guess the sourcemaps are broken! Could not set a breakpoint e.g. in rxjs/src/internal/util/pipe.ts. The browser jumps to a blank page (also not working after removing the .js.map and the location to the sourcemap in the related file)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
claudiordgzcommented, Mar 17, 2018

I always suggest everyone to read here: https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md (at least until rxjs-docs is out)

To do what you want to do I would build my own operator, like so:

let $from1 = from([1, 2]);
$from1
    .pipe(
        delay(2000),
        (yourSourceObservable) => concat(yourSourceObservable, from([3, 4])),
        delay(2000)
    ).subscribe(v => console.log(`$from1-delay-concat: ${v}`));
// $from1-delay-concat: 1
// $from1-delay-concat: 2
// $from1-delay-concat: 3
// $from1-delay-concat: 4

To pull it as your own operator

const myGloriousOperator = () => (source) => concat(source, from([3,4]));
let $from1 = from([1, 2]);
$from1
    .pipe(
        delay(2000),
        myGloriousOperator(),
        delay(2000)
    ).subscribe(v => console.log(`$from1-delay-concat: ${v}`));

I made a stackblitz on here: https://stackblitz.com/edit/rxjs-issue-3447?file=index.ts

Looking at the previous source of concat, I can see the operator was intended to be used together with another observable, such as:

Observable1.concat(Observable2)

But the pipeable operators are meant to be a function that takes in an observable and returns another observable.

So maybe we should make a concat operator that works like so concat(from([3, 4]) and would apply concat(source, from([3,4])) on it under the covers

1reaction
SerkanSipahicommented, Mar 18, 2018

Having read that (https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md) helped me a lot! Thanks for that.

Now i know why this isn’t working anymore! The pipe operator in v6 accepts only function(s) as argument(s). It’s solved totally elegantly (I believe, it’s called closure/currying), one function provides another function and the other provides an observable. The closure/currying pattern was not clear at the first glance.

… and because i am not so familiar with functional programming, i could not interpret the error message immediately.

/rxjs/node_modules/rxjs/internal/util/pipe.js:22
        return fns.reduce(function (prev, fn) { return fn(prev); }, input);
                                                       ^

TypeError: fn is not a function
    at /rxjs/node_modules/rxjs/internal/util/pipe.js:22:56

@claudiordgz Thank you so much, now everything is so clear for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multicast Operator with Pipe in RxJS 5.5+ - Stack Overflow
I get a TypeScript error when I try to use connect() like I did before: const even$ = new Subject(); const connectedSub =...
Read more >
RxJS 6: What's new and what has changed? - Auth0
Use piping instead of chaining as new operator syntax. The result of one operator is piped into another operator. Don't remove rxjs-compat until ......
Read more >
Pipe operator (%>%) does not work - RStudio Community
This is a recurring problem for me - pipe operator from dplyr package doesn't work in many cases. I'm sharing a screen recording....
Read more >
RxJS Explorer 2.0 - Reactive
Pipeable operators. Use the pipe method built into Observable . Optionally, import the pipe function to build custom and reusable operators from other...
Read more >
Transforming Data Using Pipes - Angular
However, a pure pipe with an array as input might not work the way you want. To demonstrate this issue, change the previous...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found