-
-
Save kiyoka/afe3903231307738fd56 to your computer and use it in GitHub Desktop.
Nendo sample for Enumerable::Lazy of Ruby 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
:; #-*- mode: nendo; syntax: scheme -*-;; | |
:; exec /usr/local/bin/nendo $0 $* | |
(define (grep-and-take5 in) | |
(let1 arr | |
(. | |
(. (map (lambda (x) x.chomp) in) grep #/ruby/) | |
take 5) | |
(for-each print arr))) | |
(define (main argv) | |
(with-open "test.txt" | |
(lambda (f) | |
(cond | |
((< 0 (length argv)) | |
(print "[with Lazy]") | |
(grep-and-take5 f.lazy)) | |
(else | |
(print "[without Lazy]") | |
(grep-and-take5 f))))) | |
;; print the peek memory usage of this process. | |
(with-open "|cat /proc/#{Process.pid}/status" | |
(lambda (f) | |
(print (+ "=> " (car (to-list (f.readlines.grep #/vmpeak/i)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment