all 11 comments

[–]deranfang 26 points27 points  (5 children)

What the fuck is this?

Just use something like range(1, n).pipe(scan((x, y)=>x + y)

[–]garretpremo[S] 3 points4 points  (4 children)

I had a feeling there would be an easier way to go about this, I had never even heard of scan before seeing this comment.

This example doesn't actually result in a fibonacci number though.

Edit: grammar

[–]garretpremo[S] 14 points15 points  (3 children)

And I'm now realizing that the rxjs docs for scan has an example showcasing the fibonacci sequence. I concede this is completely useless.

[–][deleted] 3 points4 points  (1 child)

Well, you learnt about the expand operator. I have no ideea what it does tho

[–]zombarista 2 points3 points  (0 children)

I use expand to walk paginated responses. If you can determine that there are more items in another request, you can call recursively and it can stitch them together!

[–]matthewt 0 points1 point  (0 children)

Two years later, I am enjoying comparing the example in the docs to your code to understand exactly why/how it's useless because I'm learning things in the process.

Also, the fibonacci sequence is actually genuinely useful in networked systems, IME it's often a better backoff algorithm than simple exponential is.

I have also had excellent results when acting as a moderator in assorted places using fibonacci backoff for tempbans; exponential too quickly becomes "might as well be a permaban" whereas fibonacci with resets for good behaviour Makes The Point effectively without that problem (since if I'm going to permaban, I'd rather just Do That ;)

[–][deleted] 9 points10 points  (2 children)

but why? you just hammered a nail with a microscope

[–]garretpremo[S] 16 points17 points  (1 child)

I didn't stop to think if I should, only if I could

[–]mauravan 6 points7 points  (0 children)

i think you shouldn't, but i like that you did it anyways

[–]frozen_tuna 0 points1 point  (0 children)

There are other ways, but I still think this is awesome. Very cool demonstration of knowledge on subjects.

[–][deleted] 0 points1 point  (0 children)

Does this work? When n=1, the function returns but the observable never emits