All Projects → tc39 → Proposal Iterator Helpers

tc39 / Proposal Iterator Helpers

Methods for working with iterators in ECMAScript

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Proposal Iterator Helpers

Tc39
360 Ecma-TC39 工作组
Stars: ✭ 75 (-76.04%)
Mutual labels:  tc39
Proposal Smart Pipelines
Old archived draft proposal for smart pipelines. Go to the new Hack-pipes proposal at js-choi/proposal-hack-pipes.
Stars: ✭ 177 (-43.45%)
Mutual labels:  tc39
proposal-function-helpers
A withdrawn proposal for standardizing some useful, popular helper functions into JavaScript’s Function object.
Stars: ✭ 41 (-86.9%)
Mutual labels:  tc39
Proposal Record Tuple
ECMAScript proposal for the Record and Tuple value types. | Stage 2: it will change!
Stars: ✭ 1,394 (+345.37%)
Mutual labels:  tc39
Javascript Style Guide
Airbnb JavaScript 스타일 가이드
Stars: ✭ 132 (-57.83%)
Mutual labels:  tc39
Esnext
介绍最新的 ECMAScript/JavaScript 规范,以及 TC39 的提案进度
Stars: ✭ 251 (-19.81%)
Mutual labels:  tc39
Meriyah
A 100% compliant, self-hosted javascript parser - https://meriyah.github.io/meriyah
Stars: ✭ 690 (+120.45%)
Mutual labels:  tc39
proposal-hack-pipes
Old specification for Hack pipes in JavaScript. Please go to the new specification.
Stars: ✭ 87 (-72.2%)
Mutual labels:  tc39
Proposal Error Cause
TC39 proposal for accumulating errors
Stars: ✭ 156 (-50.16%)
Mutual labels:  tc39
proposal-get-intrinsic
EcmaScript language proposal for a way to get intrinsics.
Stars: ✭ 19 (-93.93%)
Mutual labels:  tc39
Js Class Fields Chinese Discussion
JavaScript的『class fields』提案中文讨论
Stars: ✭ 117 (-62.62%)
Mutual labels:  tc39
Test262
Official ECMAScript Conformance Test Suite
Stars: ✭ 1,770 (+465.5%)
Mutual labels:  tc39
Javascript
JavaScript Style Guide
Stars: ✭ 117,286 (+37371.57%)
Mutual labels:  tc39
Buntis
A 100% compliant, self-hosted typescript parser that emits an ESTree-compatible AST
Stars: ✭ 90 (-71.25%)
Mutual labels:  tc39
proposal-symbol-thenable
gus.host/proposal-symbol-thenable
Stars: ✭ 18 (-94.25%)
Mutual labels:  tc39
Bigint Buffer
💪🔢 bigint-buffer: Buffer Utilities for TC39 BigInt Proposal
Stars: ✭ 26 (-91.69%)
Mutual labels:  tc39
Escaya
An blazing fast 100% spec compliant, incremental javascript parser written in Typescript
Stars: ✭ 217 (-30.67%)
Mutual labels:  tc39
dataset
The automatic track tc39 proposals
Stars: ✭ 22 (-92.97%)
Mutual labels:  tc39
legacy-decorators-migration-utility
🔝 A command line utility to upgrade your JavaScript files from the legacy decorators proposal to the new one.
Stars: ✭ 20 (-93.61%)
Mutual labels:  tc39
talk.js
🎙 A monthly meet up for all things JavaScript, Node.js, and the modern web
Stars: ✭ 75 (-76.04%)
Mutual labels:  tc39

Iterator Helpers

Proposal

A proposal for several interfaces that will help with general usage and consumption of iterators in ECMAScript. Many libraries and languages already provide these interfaces.

This proposal is at Stage 2 of The TC39 Process.

See DETAILS.md for details on semantics decisions.

See this proposal rendered here

Example usage

function* naturals() {
  let i = 0;
  while (true) {
    yield i;
    i += 1;
  }
}

const evens = naturals()
  .filter((n) => n % 2 === 0);

for (const even of evens) {
  console.log(even, 'is an even number');
}
const MyIteratorPrototype = {
  next() {},
  throw() {},
  return() {},

  // but we don't properly implement %IteratorPrototype%!!!
};

// Previously...
// Object.setPrototypeOf(MyIteratorPrototype,
//   Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));

Object.setPrototypeOf(MyIteratorPrototype, Iterator.prototype);
class ObligatoryCryptocurrencyReference extends Component {
  componentWillMount() {
    const items = ticker() // returns async iterator
      .map((c) => createElement('h2', null, `${c.name}: ${c.price}`))
      .take(5) // only consume 5 items of a potentially infinite iterator
      .toArray() // greedily transform async iterator into array
      .then((data) => this.setState({ data }));
  }

  render() {
    return createElement('div', null, this.state.data);
  }
}

Why not use Array.from + Array.prototype methods?

All of these methods (except for reduce and toArray) are lazy. They will only consume the iterator when they need the next item from it. Especially for iterators that never end, this is key. Without generic support for any form of iterator, different iterators have to be handled differently.

Prior Art

Method Rust Python npm Itertools C#
all
any
chain
collect
count
cycle
enumerate
filter
filterMap
find
findMap
flatMap
flatten
forEach
last
map
max
min
nth
partition
peekable
position
product
reverse
scan
skip
skipWhile
stepBy
sum
take
takeWhile
unzip
zip
compress
permutations
repeat
slice
starmap
tee
compact
contains
range
reduce
sorted
unique
average
empty
except
intersect
prepend
append

Note: The method names are combined, such as toArray and collect.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].