Last active
December 31, 2015 07:49
-
-
Save eiel/7956834 to your computer and use it in GitHub Desktop.
合同勉強会大都会のLTで使用したコード http://gbdaitokai.doorkeeper.jp/events/5725 捕捉はこちら http://blog.eiel.info/blog/2013/12/15/gbdaitokai-2013/ スライドはこちら。
https://speakerdeck.com/eiel/liu-reruyounipuroguramingusitai
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
-- 利用例 | |
-- $ seq 10 | runghc flow.hs | |
-- 15 | |
-- 20 | |
-- 25 | |
-- 30 | |
-- 35 | |
-- | |
-- 入力を待たないけどコードを逆から読まないといけない | |
main = do | |
getContents >>= ( | |
return . | |
take 5 . -- 最初の5個 | |
filter (>10) . -- 10より大きいものだけに | |
map (*5) . -- 5倍する | |
map read . -- 数値に | |
lines | |
) >>= mapM_ print |
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
# 利用例 | |
# $ seq 10 | ruby flow.rb | |
# 15 | |
# 20 | |
# 25 | |
# 30 | |
# 35 | |
# | |
# 標準入力の読み込みが終わらないと動いてくれない | |
puts ARGF.each_line | |
.map(&:to_i) # 数値に | |
.map { |n| n * 5} # 5倍する | |
.select { |n| n > 10 } # 10より大きいものだけに | |
.first(5) # 最初の5つ |
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
-- 利用例 | |
-- $ seq 10 | runghc flow_arrow.hs | |
-- 15 | |
-- 20 | |
-- 25 | |
-- 30 | |
-- 35 | |
-- | |
-- Haskell には Control.Arrow があるじゃない | |
import Control.Arrow | |
main = getContents >>= ( | |
lines | |
>>> map read -- 数値に変換 | |
>>> map (*5) -- 5倍する | |
>>> filter (>10) -- 10より大きいものだけに | |
>>> take 5 -- 最初の5個 | |
>>> return | |
) >>= mapM_ print |
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
# 利用例 | |
# $ seq 10 | runghc flow_lazy.hs | |
# 15 | |
# 20 | |
# 25 | |
# 30 | |
# 35 | |
# | |
# ruby 2.0 以降なら Enumerator::Lazy があるじゃない | |
ARGF.each_line | |
.lazy | |
.map(&:to_i) # 数値に | |
.map { |n| n * 5 } # 5倍する | |
.select { |n| n > 10 } # 10より大きいものだけに | |
.map { |n| puts n } # 出力 | |
.first(5) # 最初の5個 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment