-
Notifications
You must be signed in to change notification settings - Fork 3k
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
partition makes no sense as a lettable/pipeable operator #2995
Comments
I wonder if it would make sense to change const source = of(1, 2, 3, 4)
// partition
const [odds, evens] = flow(
map(x => x * 2),
partition
)(source)
const [odds, evens] = source
.pipe(map(x => x * 2))
.pipe(partition)
// toPromise
await flow(
map(x => x * 2),
toPromise
)(source)
await source
.pipe(map(x => x * 2))
.pipe(toPromise) |
I would like to change the typings for Changing to something like this would do it: pipe<A, OA extends Observable<A>>(
op1: UnaryFunction<Observable<T>, OA>
): OA;
pipe<A, B, OB extends Observable<B>>(
op1: OperatorFunction<T, A>,
op2: UnaryFunction<Observable<A>, OB>
): OB;
// etc. It should be straight forward to provide some additional overload signatures so that the last operator can return a something other than an observable - which could then be returned by Whether or not this is desirable, I don't know. I've not spent too much time weighing up the pros and cons. However, if Given that I cannot recall using |
As a thought, the suggestion by @felixfbecker to make |
If the
|
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 |
Same here. Need more clarification. |
@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(). |
Using @bratter defintion of the
|
Current If it's an operator, it should be |
@benlesh Static would make the most sense, I think. Essentially, it's the reverse of |
@cartant @benlesh When you say static do you mean a function in I was able to use partition as follows:
https://stackblitz.com/edit/partition?file=index.ts If it was a function in |
@claudiordgz I think we're talking about |
@benlesh thank you, last question... would it be under observable or under util? |
RxJS version: 5.5.1
partition
is one of the new lettable/pipeable operators in theoperators
directory. However, it's not really lettable, as it does not return anObservable
:And with it defined as it is, the usage is somewhat clumsy:
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 topipe
(or tolet
)?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)?The text was updated successfully, but these errors were encountered: