Todos os livros

Profissional

Apps Sobre Coach Entrar Começar a ler

Computer Science · Glossário

O que é Lazy iterator, iterator adaptor?

Também chamado de: lazy iterator · iterator adaptor

Definition 9.4 University Computer Science — Year 2 · Capítulo 9 — Functional Programming

A Rust iterator is lazy: it computes the next element only when next is called. An iterator adaptor (map, filter, take, …) wraps an iterator into a new one and does no work when created; a consumer (sum, collect, count, a for loop) calls next until the end or until it has enough.

A lazy pipeline is pulled by its consumer. collect asks take for an element, which asks filter, which asks map until one passes; after two, take stops asking, and 320 is never mapped.
A lazy pipeline is pulled by its consumer. collect asks take for an element, which asks filter, which asks map until one passes; after two, take stops asking, and 320 is never mapped.
Ler no capítulo →