Giter Site home page Giter Site logo

labs42io / itiriri Goto Github PK

View Code? Open in Web Editor NEW
176.0 11.0 8.0 341 KB

A library built for ES6 iteration protocol.

Home Page: https://labs42io.github.io/itiriri

License: MIT License

TypeScript 99.94% Dockerfile 0.06%
iterators iterable filter collections map lazy slice for-of

itiriri's People

Contributors

asimionese avatar dimadeveatii avatar johndoeplusplus avatar jrr avatar keloo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

itiriri's Issues

Document, optimize code size for client-side use?

A frequent PITA with utility libraries like this is bad behavior when trying to optimize code size in webpack, et al. I'm no expert at this, so I can't make specific recommendations. But folks need to know whether the documented import style

import { map } from 'itiriri';

sucks in a lot of irrelevant code in production, and if so, how they should avoid that. If it works great as documented, you should say that, too, so folks like me don't pester you.

Async generators?

Just wanted to see if you've considered supporting the asynchronous iteration protocol (like from async generators) with the itiriri API?

async function *getFiles(urls) {
   var prs = urls.map(fetch);
   for (let pr of prs) {
      let file = await pr;
      yield file;
   }
}

var files = itiriri( getFiles([ "url1", "url2", "url3" ]) ).take(2);

for await (let file of files) {
   console.log(file);
}

Export the Itiriri class

If you don't mind me asking, why is the main Itiriri class not exported? It would make it easier to extend it and add more methods.

As it stands, one is left with two options, both sub-optimal:

  • copy the entire source of the Itiriri class, just to add a couple metods
  • fiddle with prototypes at runtime

Right now I'm going with option 2:

import itiriri, { IterableQuery } from 'itiriri'
import equal from '@wry/equality'

// extend the IterableQuery interface for the type checker
declare module 'itiriri' {
  export interface IterableQuery<T> {
    /**
     * Returns `true` if this sequence is equal to the given sequence.
     */
    equals(other: Iterable<T>): boolean
  }
}

// export a function with a new name so that the IDE knows to import from here
export default function from<T>(source: Iterable<T>): IterableQuery<T> {
  return itiriri(source)
}

// HACK: obtain a reference to the Itiriri class from an instance
const Itiriri = itiriri([]).constructor

// implement the extensions
Itiriri.prototype.equals = function <T>(other: Iterable<T>): boolean {
  const as = this[Symbol.iterator]()
  const bs = other[Symbol.iterator]()
  while (true) {
    const a = as.next()
    const b = bs.next()
    if (a.done && b.done) return true
    if (a.done !== b.done || !equal(a.value, b.value)) return false
  }
}

Client code:

import from from '../lib/from'

// ...
  from(someArray)
    .map((it) => it.value)
    .take(somePrefix.length)
    .equals(somePrefix)
// ...

zip function ?

Suppose l1: Iterable<S> and l2: Iterable<T>, then it would be nice to be able to do something like itiriri(l1).zip(l2).map( ([x, y]) => f(x, y) ), for example.
I believe with the latest TypeScript features, zip's generics can be variadic so an arbitrary number of other iterables can be zipped in.

Chunk method?

Hi! Cool library!
Can you add a chunk method like this?

Example:

function* lazy(){
   //yield 10K promises
}

itiriri(lazy())
   .chunk(1000)
   .forEach(async function(chunk){
      await Promise.all(chunk);
   });

So many implementations :)

I keep finding more and more libraries like this, after I started working on one of my own - iter-ops, which is both quite different and yet similar to what you are doing here ๐Ÿ˜„

Just wanted to say hi, nice work, and I enjoy going over the list of operators here, to see what I may have missed that might be important.

Perhaps the reason I didn't find it earlier is its complex name ๐Ÿ˜„

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.