let line_stream_of_channel channel = Stream.from (fun _ -> try Some (input_line channel) with End_of_file -> None);; let list_of_stream stream = let result = ref [] in Stream.iter (fun value -> result := value :: !result) stream; List.rev !result ;;
As an example, this line calls print_string on every element read from stdin:
List.iter print_string (list_of_stream (line_stream_of_channel stdin)) ;;
No comments:
Post a Comment