Last active
March 2, 2019 23:24
-
-
Save alejandrolechuga/26051409f3adf449364e4e42f66dd1e0 to your computer and use it in GitHub Desktop.
Iterables and iterators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = ['a', 'b', 'c']; | |
const iterador = arr[Symbol.iterator](); | |
iterador.next(); | |
// { value: 'a', done: false } | |
iterador.next(); | |
// { value: 'b', done: false } | |
iterador.next(); | |
// { value: undefined, done: true } | |
/// Only for linear data strutures | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES6 | |
Introdujo un nuevo mecanismo para poder recorrer datos. LLamador iteracion. Existen dos conceptos que parte central de la iteracion | |
- Un Iterable , es un estructura de datos que esta hecha para hacer publicos sus elementos | |
Y lo hace mediante un metodo que una frabrica de iteradores (iterators) | |
y La llave de acceso para este metodo es atraves del Simbolo "Symbol.iterator" | |
- Un Iterador es un apuntador para recorrer los elementos de la estructura de datos | |
Cuales son los valores iterables | |
- Arrays | |
- Strings | |
- Maps | |
- Sets | |
- DOM -> Estructura de Datos para el HTML | |
Estructuras del lenguaje qque accesan datos atraves la iteracion | |
- Desestruracion | |
const [a, b] = new Set(['a', 'b', 'c']); | |
- for of loop | |
for (const x of ['a', 'b', 'c']) { | |
console.log(x); | |
} | |
- Array.from | |
const arr = Array.from(new Set(['a', 'b', 'c')]) | |
- Operador Spread ... | |
const arra = [... new Set(['a', 'b', 'c']] | |
- Constructors of Maps and Sets | |
const map = new Map([[false, 'no'], [true, 'yes']]); | |
const set = new Set(['a', 'b', 'c']); | |
- Promise.all Promise.race | |
Promise.all(iterableOverPromises).then() | |
Promise.reace(iteralesOverPromises).then() | |
- yeld * | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
La idea de iterabilidad es como sigue | |
- Data Consumers: | |
Consumidores de datos: Las estructuras que consumen datos, por ejemplo for of recorrer valores y el operador spread inserta valores en un arreglo o en llamada | |
de funciones. | |
- Data Sources: | |
Son las fuentes por donde elos consumidores obtienen sus datos | |
ES6 tiene la inteface Iterable donde data consumers lo utilizan y data sources lo implemnetan | |
Grafico | |
http://exploringjs.com/es6/images/iteration----consumers_sources.jpg | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment