partition makes no sense as a lettable/pipeable operator
See original GitHub issueRxJS version: 5.5.1
partition
is one of the new lettable/pipeable operators in the operators
directory. However, it’s not really lettable, as it does not return an Observable
:
export function partition<T>(
predicate: (value: T, index: number) => boolean,
thisArg?: any
): UnaryFunction<Observable<T>, [Observable<T>, Observable<T>]> {
return (source: Observable<T>) => [
filter(predicate, thisArg)(source),
filter(not(predicate, thisArg) as any)(source)
] as [Observable<T>, Observable<T>];
}
And with it defined as it is, the usage is somewhat clumsy:
const source = of(1, 2, 3, 4);
const [odds, evens] = partition(value => value % 2)(source);
Are all of the operators in the operators
directory supposed to be lettable? Should it be defined elsewhere? And in a way that makes its calls more straightforward? That is, is there any point in its returning a function if that function cannot be passed to pipe
(or to let
)?
The solution for toPromise
was to move it to the prototype, but is there are alternative solution for these types of ‘operators’ (if that term is even appropriate)?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:14 (5 by maintainers)
Top Results From Across the Web
RxJS: Understanding Lettable Operators
Lettable operators offer a new way of composing observable chains and they have advantages for both application developers and library ...
Read more >Call asynchronous operations in RxJS operators-rx.js
One way to do this is to: use flatMap to call the async function, returning both the value and the result to be...
Read more >rxjs/CHANGELOG.md
- Our very new creation function, `connectable`, now takes a configuration object instead of just the `Subject` instance. This was necessary to make...
Read more >rxjs | Yarn - Package Manager
Complete notifications no longer end the duration. throttle: the observable returned by the throttle operator's duration selector must emit a next notification ...
Read more >Untitled
Gone for a burton meaning, Chu ky ten danh, Jon snow all scenes season 1, Kako zakrpiti ... Atletico de tucuman vs temperley,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@maxime1992, @crimx, not sure if you were suggesting you’d solved or not, but if not… you need to do as follows:
Note that the partition function returns a function that has to then be called with the source observable as per felix’s comment above, and therefore cannot be used with pipe().
Indeed, I thought I could do something like that:
But it ends up with the following error:
Repro: https://stackblitz.com/edit/angular-fwfubg?file=app%2Fapp.component.ts