Comments (8)
It is desirable that given an iterable
:
Iterum(iterable)
behaves likeiterable
with for...of and spread operator.- callback of
Iterum(iterable)
methods (map
,filter
,some
, etc) traverse the samevalue
andkey
thatforEach
method of built-in javascript iterables.
from iterum.
Repeat
constructor will be deprecated and a .repeat()
method with signature similar to String.prototype.repeat will be implemented.
from iterum.
- callback of
Iterum(iterable)
methods (map
,filter
,some
, etc) traverse the samevalue
andkey
thatforEach
method of built-in javascript iterables.
In order to implement this, almost built-in iterables has .entries()
that returns an iterable that iterates throw [key, values]
.
- In Map, these values are the keys and values of the Map instance.
- In Array, TypedArray, the keys are the indexs.
- In Set, the keys and values are the same
Iterum(iterable)
will have a method .entries
that returns the same iterable as iterable.entries()
. If iterable does not have method entries
(String), then default entries will be implemented like that:
function* entries () {
let index = 0
for (let val of iterable) {
yield [index, val]
++index
}
}
Then, all of Iterum methods that use callbacks (map
, filter
, some
, etc) will be implemented using .entries
method to be consistent.
from iterum.
Problems implementing methods based on entries
Given the following sentence:
const iterable = Iterum(new Map([['one', 1], ['two', 2]])).concat(new Map([['one', 5], ['three', 3]]))
- methods with callbacks iterates over keys with the same value.
- Method indexOf has weird behaviour:
const index = iterable.findIndex(e => e === 5) // returns 'one'
iterable.slice('one') // returns iterable -> because the first key is also 'one'
Therefore, I think that is better go back and implement Iterum instances that behaves like an array with numeric indexes.
from iterum.
Iterum aims to provide array-like methods emulating the behaviour of arrays in iterables but using lazy evaluation. However this approach is only possible imitating methods that return an array. For example, given methods of Array that return an array (map, filter, concat, slice) can be replicated in Iterum class like a methods that return Iterum instances. But imitating array methods that return other values (reduce, indexOf, find, etc) is not possible to do chaining and, then, lazy evaluation is also not possible.
For that, I think that is important increase the list of Iterum methods that return another iterable. I think that the good example is keeping the same nomenclature than lodash
methods. In order to expand the ecosystem of methods, it's interesting to implement dropWhile
, takeWhile
, drop
and take
.
For example:
const iterumDropWhile = iterum.dropWhile(cb, context)
is the lazy version of:
const index = iterum.findIndex((e, i, itm) => !cb(e, i, itm), context)
const iterumDropWhile = iterum.slice(index)
const iterumTakeWhile = iterum.takeWhile(cb, context)
is the lazy version of:
const index = iterum.findIndex(cb, context)
const iterumTakeWhile = iterum.slice(0, index)
from iterum.
Iterum.compose
it is useful function that is used to compose generators and lazy implementation of cartesian product of iterables (Iterum.cartesian) and also is used in other packages like siteswap-generator. However the new iterum
package works with iterables and not generators. Then this function should be extracted to another package.
from iterum.
Currently, an Iterum iterable that produces some Iterum value is expanded automatically. For example:
const iterable = Iterum([1, Iterum([2, 3, 4]), 5])
[...iterable] // returns [1, 2, 3, 4, 5] and not [1, Iterum([2, 3, 4]), 5]
I think that this behaviour is weird by default. I think that is preferable that Iterum instances does not have privileges over other iterables. If is required to expand an iterable inside other iterable, it is possible to use something like flatten lodash function.
Then, Iterum
autoexpandability should be removed and flatten
method should be created.
from iterum.
Which is the criteria to decide if a method has static implementation or not?
For example, cartesian
is a static methods that allows iterable instances. However it is possible to create a method like that:
Iterum([1, 2]).cartesian([3, 4]) // potentially [[1, 3], [1, 4], [2, 3], [2, 4]]
Actually, all of object methods can be transformed to static methods. Instead all static methods cannot be tranformed to object methods (see range
static method). Then, as I don't find criteria to decide if method should be static or not, any object method will have its corresponding static method and the user is free to choose what to use.
from iterum.
Related Issues (20)
- Implement lazy cartesian product HOT 3
- implement `power` method
- implement `combinations` method HOT 1
- Removing optional arguments in methods. HOT 4
- removing forEach method
- removing `fromIndex` arguments. HOT 2
- Implement `has` & `nth` methods
- Add benchmarks HOT 4
- permutations method must work with infinite iterables
- remove default behaviour of Iterum functions if first parameter is not an iterable.
- adapt functions to functional style (iterable last) HOT 3
- currying functions
- add powerset method and function
- add variations (k-permutations) method and function
- implement zipLongest & transposeLongest
- implement `tap`
- implement chunk
- implement toString
- Implement cycle
- adapt indexOf to use sameValueZero specification for equality
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iterum.