labs42io / itiriri Goto Github PK
View Code? Open in Web Editor NEWA library built for ES6 iteration protocol.
Home Page: https://labs42io.github.io/itiriri
License: MIT License
A library built for ES6 iteration protocol.
Home Page: https://labs42io.github.io/itiriri
License: MIT License
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.
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);
}
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:
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)
// ...
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.
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);
});
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 ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.