Giter VIP home page Giter VIP logo

Comments (9)

rpominov avatar rpominov commented on August 19, 2024

Another approach would be to swap seed and fn arguments so it will be .diff(fn, seed) instead of .diff(seed, fn). Then it will become clear which argument is omitted:

  • diff(a) — seed omitted
  • diff(null, a) — fn omitted
  • diff() — both

But it's a breaking change ...

from kefir.

chicoxyzzy avatar chicoxyzzy commented on August 19, 2024

Another approach would be to swap seed and fn arguments so it will be .diff(fn, seed) instead of .diff(seed, fn).

These sounds like proper way. Same order as in Array.prototype.reduce.

BTW how about diff(seed, fn), diff(seed), diff() and diffByFunction(fn) (or simply diffBy(fn))?

from kefir.

rpominov avatar rpominov commented on August 19, 2024

Yeah, I am also thinking of doing swapping.
But not sure about diffByFunction / diffBy, diff(null, a) is good enough.

from kefir.

chicoxyzzy avatar chicoxyzzy commented on August 19, 2024

Kefir uses semver so nothing stops you to make breaking changes in next major version.
Also something like diff(_.noop, seed) looks much better then diff(null, seed) I think. But there is another issue when you really need to return undefined value in diff function.

from kefir.

chicoxyzzy avatar chicoxyzzy commented on August 19, 2024

Now I think diff(null, seed) is ok. As it in Node.js callback error conventions and in some other libraries.

Just noticed, documentation says that

If no fn function provided, function(a, b) {return [a, b]} will be used as default.

Why not just identity function of new value?
Also I believe that swapped order (i.e. function (next, prev) { /* ... */}) is more traditional. Diffs algorithms in all major libraries and frameworks use that order. In this way you can just omit old value in callback function if you don't need it.

from kefir.

rpominov avatar rpominov commented on August 19, 2024

Now I think diff(null, seed) is ok

Yes, we can't use _.noop, because it will result in observable always emitting undefined (which _.noop always return).

Why not just identity function of new value?

If function(a, b) {return b} was used, then a.diff(seed) would be equivalent of just a.

from kefir.

chicoxyzzy avatar chicoxyzzy commented on August 19, 2024

Yes, we can't use _.noop, because it will result in observable always emitting undefined (which _.noop always return).

But I mean diff(_.noop, seed) not diff(_.noop(), seed). _.noop itself is not undefined but function so it'll be used as diff function returning null.

If function(a, b) {return b} was used, then a.diff(seed) would be equivalent of just a.

That makes sense.

from kefir.

rpominov avatar rpominov commented on August 19, 2024

so it'll be used as diff function returning null

yep, and that null will be emitted from result observable. That what I am trying to say)

from kefir.

chicoxyzzy avatar chicoxyzzy commented on August 19, 2024

oh I just hasn't realized that we are speaking about same things sorry

from kefir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.