Giter Site home page Giter Site logo

Comments (4)

Sawtaytoes avatar Sawtaytoes commented on May 18, 2024 2

Or better yet, why not match RxJS's import style? I would assume most users of IxJS would be RxJS folks not wanting to learn another transducer library. Is that assumption correct?

If so, wouldn't ixjs/operators make the most sense?

Also, I noticed this example was wrong as well:

// ES
import { AsyncIterableX as AsyncIterable } from 'ix/asynciterable';
import { filter, map } from 'ix/asynciterable/pipe';

// CommonJS
const AsyncIterable = require('ix/asynciterable').AsyncIterableX;
const { filter, map } = require('ix/asynciterable/pipe');

const source = async function* () {
  yield 1;
  yield 2;
  yield 3;
  yield 4;
};

const results = from(source()).pipe(
  filter(async x => x % 2 === 0),
  map(async x => x * x)
);

for await (let item of results) {
  console.log(`Next: ${item}`);
}

In this example, AsyncIterable is imported, but from is never imported directly. Should it be AsyncIterable.from instead? Or even better, from or fromPromise which doesn't require pulling values off an object.

In RxJS, you can use from for Array, Iterable, Promise (async), and Observable so I would imagine IxJS would be able to tell if it's dealing with Iterable vs AsyncIterable in the same way; although, I dunno if it would be as simple as it is with RxJS's from.

Either way, having a separate iterator method would help with tree-shaking and ensure more similarities to RxJS.

from ixjs.

desnor avatar desnor commented on May 18, 2024

I had a quick look through and to explain what's happening with your points respectively:

  • The of operator comes from above Iterable object. So this example should really be Iterable.of
  • The import { map, filter } from 'ix/iterable/pipe'; doesn't do what we expect here because import ... from 'ix/iterable/pipe' returns us the function pipe not the subdirectory which contains the pipe-able (lettable) functionality. In order to access the map and filter lettable functions we need to dig deeper and actually go into the 'pipe' subdirectory. So for ex. something like import { map, filter } from 'ix/iterable/pipe/'

Does that make sense? It's not ideal having these names clash. I'll make a pull request to the docs updating the above points and see if anyone has an opinion about a different way to get access to the lettable functions. Maybe a directory called lettable instead of pipe would be a good start?

from ixjs.

desnor avatar desnor commented on May 18, 2024

Bit more info from doing this:

require.resolve('ix/iterable/pipe');
=> .../ix/node_modules/ix/iterable/pipe.js

whereas
require.resolve('ix/iterable/pipe/');
.../ix/node_modules/ix/iterable/pipe/index.js

from ixjs.

OliverJAsh avatar OliverJAsh commented on May 18, 2024

@desnor That makes sense to me!

from ixjs.

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.