ReadStream en Smalltalk
Recorre una colección con un cursor.
"A ReadStream walks a collection with a cursor."
| feed |
feed := ReadStream on: #('frisket' 'tympan' 'platen' 'chase').
Transcript show: 'First out: ', feed next; cr.
Transcript show: 'Then: ', feed next; cr.
Transcript show: 'Peek: ', feed peek; cr.
Transcript show: 'Still next: ', feed next; cr.
[feed atEnd] whileFalse: [
Transcript show: 'Draining: ', feed next; cr].
Transcript show: 'Empty? ', feed atEnd printString; cr.
Cómo funciona
nextconsume un elemento;peekmira sin tomar.atEndguarda el bucle de drenado.- Los streams unifican colecciones y archivos tras un protocolo.
El intento, en números
- Líneas
- 12
- Caracteres a escribir
- 431
- Tokens
- 77
- Ritmo de tres estrellas
- 60 tpm
Al ritmo de tres estrellas de 60 tokens por minuto, este intento toma unos 77 segundos.
Paso 2 de 2 en Streams; paso 25 de 31 en Fundamentos del lenguaje.