Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 07 20:08

    dependabot[bot] on npm_and_yarn

    (compare)

  • May 07 20:08

    staltz on master

    chore(deps): bump ini from 1.3.… (compare)

  • May 07 20:08
    staltz closed #322
  • May 07 19:58

    dependabot[bot] on npm_and_yarn

    (compare)

  • May 07 19:58

    staltz on master

    chore(deps): bump hosted-git-in… (compare)

  • May 07 19:58
    staltz closed #321
  • May 07 19:47

    dependabot[bot] on npm_and_yarn

    (compare)

  • May 07 19:47
    dependabot[bot] closed #318
  • May 07 19:47
    dependabot[bot] commented #318
  • May 07 19:47
    dependabot[bot] labeled #322
  • May 07 19:47
    dependabot[bot] opened #322
  • May 07 19:47

    dependabot[bot] on npm_and_yarn

    chore(deps): bump ini from 1.3.… (compare)

  • May 07 19:47
    dependabot[bot] edited #318
  • May 07 19:46
    dependabot[bot] labeled #321
  • May 07 19:46
    dependabot[bot] opened #321
  • May 07 19:46

    dependabot[bot] on npm_and_yarn

    chore(deps): bump hosted-git-in… (compare)

  • May 07 19:46
    dependabot[bot] edited #318
  • May 07 19:45

    staltz on npm_and_yarn

    (compare)

  • May 07 19:45

    staltz on master

    chore(deps): bump handlebars fr… (compare)

  • May 07 19:45
    staltz closed #320
Nikhil Tilwalli
@ntilwalli
I agree that as a beginner that nuance can be confusing...
Michal Vanko
@michalvankodev
I actually understand the concept behind it. I still might be confused as I am not relying on it yet. But still just trying to think of a use case in my app that I would actually want this behavior.
Nikhil Tilwalli
@ntilwalli
There's no real utility. It like creating an Integer class that stores its one internal value inside an array
The interface still operates as if it's a single unit
I dunno if that's the best analogy, but yeah, I can't think of a use-case...
Other than speed
Michal Vanko
@michalvankodev
Please alert me when you do. This is really important actually :)
Nikhil Tilwalli
@ntilwalli
:thumbsup:
André Staltz
@staltz
@michalvankodev without unicast we can't have referential transparency (purity) everywhere
here's a basic example:
    const inc$ = sources.DOM.select('.inc').events('click').mapTo(+1);
    const refresh$ = sources.DOM.select('.ref').events('click').startWith(0);
+   const sum$ = inc$.fold((x, y) => x + y, 0);
+   const lastSum$ = refresh$.map(_ => sum$).flatten();
-   const lastSum$ = refresh$.map(_ => inc$.fold((x, y) => x + y, 0)).flatten();
    const vdom$ = lastSum$.map(count =>
      div([
this simple refactoring changes program behavior
cyclejs/cyclejs#365
Nikhil Tilwalli
@ntilwalli
@staltz Am I right that your example has varying behavior in xstream but not in RxJS?
By my understanding since xstream does an async unsubscribe (under the hood) during flatten the new subscriber will be added before the old one is removed ensuring the sum$ never goes down to zero subscribers, thus causing it to never reset. RxJS does synchronous unsubscribe during switchMap thus in RxJS the sum$ would go from one down to zero subscribers temporarily before immediately adding the new subscriber and going from zero back to one subscriber (resetting it). The reset from zero subscribers would happen in either version of the code...
Nikhil Tilwalli
@ntilwalli
The unicast/multicast referential transparency issue is exposed when sum$ has subscribers other than lastSum$. No matter the lib, xstream or RxJS, in the sum$ example, the number of subscribers will never go down to zero so the stream will never get reset, whereas in the commented-out version a new stream reference (with zero existing subscribers) is created on every refresh$ emission...
André Staltz
@staltz
@ntilwalli did you test that in RxJS? I don't think RxJS would have this issue becaues xstream does sync-start, async-stop, so when switching to the same inner stream as the previous, in xstream no unsubscribe of the inner will happen
in RxJS, switchMap does sync-start, sync-stop, so it will unsubscribe
furthermore, there's no multicasting and refcounting in RxJS's sum$ in that example, unless you explicitly choose it
Nikhil Tilwalli
@ntilwalli
I thought that's what I said. In RxJS the subscriber count will go down to zero so the stream will reset, in xstream the subscriber count will not go down to zero, so the stream will not reset
The variance comes from whether the stream resets or not...
In RxJS it will reset regardless of whether a stream reference is reused or not. In xstream reusing the reference causes the stream to not reset...
Nikhil Tilwalli
@ntilwalli
You reminded me of the referential transparency issue which I'd forgotten about. :) I was just pointing out that if you add an additional subscriber, the example (which right now only exposes the issue in xstream) would also demonstrate the issue in RxJS
André Staltz
@staltz
Nikhil, you mean with multicasting in RxJS, right? Just want to clarify that "subscriber count" only exists with subjects and with refCounting
Nikhil Tilwalli
@ntilwalli
Yes, that's what I meant. Agreed :thumbsup:
Steve Lee
@SteveALee
can see in node_modules, node_modules\cycle-restart\node_modules and node_modules\cyclejs-test-helpers\node_modules
is tree shaking enabled and working now?
oops, wrong convo!
Вячеслав Истомин
@shofel

It looks like xs.of() is the same as 'xs.empty()'.
I was expecting xs.of() equals to xs.of(null) or somewhat. Now I see the actual behaviour does make sense, but at first it's not as obvious.

Maybe we should mention this in the description of xs.of? I mean, equivalence of xs.of() without args and xs.empty().

André Staltz
@staltz
Hi @shofel, I think xs.of() should be the same as xs.of(undefined), so it's not the same as xs.empty()
Вячеслав Истомин
@shofel

@staltz, my intuition was the same as you wrote.

As for now, xs.of() and xs.of(undefined) behave differently.

xs.of() completes immediately, not emmiting anything. (|)

But xs.of(undefined) emits undefined and completes immediately. (undefined|)

https://runkit.com/59c12300c3b4c40012a5260e/59c1230162f5730012fd3b86

André Staltz
@staltz
oh, correct! the args in function of(...args) is empty array
you were right
Alex
@whitecolor
also merge() and combine() are the same as empty() =)
Serge Havas
@Sinewyk
Hey, when working on cyclejs/cyclejs#736 I was bitten by the fact that streams can start emitting values synchronously. I'm coming from most where they enforced that values should always start emitting asynchronously.
So 1/ For academics reasons: why did you settle that starting to emit values could happen synchronously ? 2/ I think it need to be made clearer around here https://github.com/staltz/xstream#how-a-stream-starts-and-stops or above, that yes, writing this code
console.log(0)
xs.of(1).subscribe({next: n => console.log(n)});
console.log(2);

will yield

0
1
2

and not

0
2
1

As I first believed.

Which means that sometimes you can access the subscription inside the subscribe handlers, and sometimes you can't. Which is super important IMO.
Serge Havas
@Sinewyk
Any idea how to use replaceError with typescript ?
I'm using it to transforms a stream of strings into a stream of errors, but replaceError seem to absolutely want to keep the signature of the stream we are using it on, am I doing something wrong ?
Serge Havas
@Sinewyk
argggggg, again, I got bitten by the fact that event can and will happen synchronously when they can, got to remember that, sprinkling remember() will ensure that even though event happened, subscribing after will still get me where I want
Вячеслав Истомин
@shofel

Hello!

Could anyone suggest how to transform
a stream

0, 1, 2, 3, ...

to

[0, 1], [1, 2], [2, 3], ...
Serge Havas
@Sinewyk
fold + filter I would say
you fold to push events into an array, while limiting the size 1 array by filtering it out
Вячеслав Истомин
@shofel
Yeah, indeed. I've got it. Thank you.
Вячеслав Истомин
@shofel

Just giving back)

  /* *
   * A pair data structure.
   * Like an array but 
   *  - You can only push and get values.
   *  - Its length is never greater than 2. Two the most recently pushed elements.
   */

  /* @util */
  let push = x => xs => {
    let xs_ = xs.slice()
    xs_.push(x)
    return xs_
  }

  let Pair = (values = []) => {
    let pushToPair = x => Pair(push(x)(values).slice(-2))
    return {values, push: pushToPair}
  }

  let refreshPair = (pair, x) => pair.push(x)

  /**
   * Stream operator.
   * 
   * `----1---2-----3-----4--------|`
   * .compose(slidingLastPair)
   * `[]--[1]-[1,2]-[2,3]-[3,4]----|`
   */
  let slidingLastPair = $ =>
    $.fold(refreshPair, Pair())
    .map(prop('values'))

  /**
   * Example
   */

  let pair$ =
    xs.of(1, 2, 3, 4)
    .compose(slidingLastPair)

@Sinewyk, what do you think is a better name for this operator?

Serge Havas
@Sinewyk
Hmm, it seems like a sliding window more generally, but what you have is good
I would just use more ramda :laughing:
André Staltz
@staltz
I think we already have an operator for that: pairwise
it's an extra operator
Marco Toniut
@marcotoniut

@marcotoniut
Hey everyone, I finally managed to pinpoint a bug my program had to this localized piece of code

test('combine', t => {
    const s$ = Stream.of(Stream.of(1), Stream.of(2), Stream.of(3))
        .map(x => x.remember())
        .fold((acc: Stream<number>[], x: Stream<number>) => [...acc, x], [] as Stream<number>[]).debug('collection')
        .map(ss => combine(...ss)).flatten().debug('combined');
    // return s$.take(1).map(x => t.deepEqual(x, []));
    // return s$.last().map(x => t.deepEqual(x, [1, 2, 3]));
    return combine(s$.take(1), s$.last()).map(([x, y]) => {
        t.deepEqual(x, []);
        t.deepEqual(y, [1, 2, 3]);
    });
});

From what I can gather, the problem is that after the s$.take(1) stream is travelled, the source streams in combine aren't re-triggering the events for s$.last() to complete
Therefore, the combined s$.take(1) and s$.last() never finishes
Is there a way to prevent this from happening? I thought remember was supposed to re-trigger the event when a new stream was hooked to it