cujojs / most

Ultra-high performance reactive programming
MIT License
3.5k stars 231 forks source link

Scan emits `undefined` when no initial value provided #462

Closed 1ven closed 7 years ago

1ven commented 7 years ago

Summary

When running scan without initial value, it emits undefined as a first value. Or it's correct behaviour and I'm understanding it wrong?

Expected result

It should not emit undefined when no initial value provided.

Versions

Code to reproduce

// Emits `undefined` first
stream$.scan((acc, fn) => fn(acc));
briancavalier commented 7 years ago

Hey @1ven. The initial value is a required parameter. The convention in the docs is that unless a parameter is explicitly called out as optional, it's required. Perhaps it's a bit more obvious in scan's type definition, though.

So, as things go in JS, by not passing a value, you're implicitly passing undefined, and scan always produces it's initial value as its first event.

Sorry for any confusion. Hope that helps.

1ven commented 7 years ago

Hi, now it's clear, thanks for clarification :)

briancavalier commented 7 years ago

Great, glad that helped.

1ven commented 7 years ago

The problem is solved by using .skip(1) method