import java.util.List;
import java.util.stream.Stream;

/** Los streams son lazy: nada corre hasta la terminal, y limit corta antes. */
public class LazyDemo {

    public static void main(String[] args) {
        List<Song> songs = Songs.sample();

        Stream<String> pipeline = songs.stream()
                .filter(s -> {
                    IO.println("  filter " + s.title());
                    return s.seconds() < 215;
                })
                .map(s -> {
                    IO.println("  map    " + s.title());
                    return s.title().toUpperCase();
                });
        IO.println("pipeline armado, sin operación terminal todavía");

        List<String> firstTwo = pipeline.limit(2).toList();
        IO.println("resultado: " + firstTwo);
    }
}
