Come si chiama un iteratore che ha dato una lista [a, b, c]
, restituisce un oggetto della forma { prev, curr, next }
per ogni iterazione?
ad es. (? === undefined
)
{ prev: ?, curr: a, next: b }
{ prev: a, curr: b, next: c }
{ prev: b, curr: c, next: ? }
Ho pensato tuples
, ma sono abituato a pensare che una tupla sia di solito un elenco di 2 voci quindi sono indeciso.
EDIT: Triples could work, but I was also wondering if there is any mention of this type of structures in the literature. I am familiar with linked lists, but this is different.
EDIT 2: Here is the generator implementation in JavaScript.
/**
@syntax
Parsec.prototype.tuples([a, b, c])
{ prev: ?, curr: a, next: b }
{ prev: a, curr: b, next: c }
{ prev: b, curr: c, next: ? }
@param {Array|String} list List to iterate.
@param {Object} [last] Define to use as the last value.
@param {Object} [prev] Define to use as the first prev value.
@param {Object} [curr] Define to use as the first curr value.
*/
function* tuples(list, last, prev, curr) {
for (let next of list) {
if (curr !== undefined) yield { prev, curr, next /* add last here? */}
prev = curr
curr = next
}
yield { prev, curr, last }
}