Last active
December 18, 2015 17:09
-
-
Save chomado/5816872 to your computer and use it in GitHub Desktop.
Lispみたいな式を簡単に書く練習メモ(すごいHaskell本より)
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
-- 関数適用演算子$ | |
sum (filter (> 10) (map (* 2) [ 2 .. 10])) | |
sum $ filter (> 10) $ map (* 2) [ 2 .. 10] | |
-- 関数合成. | |
map (\x -> negate (abs x)) [5, -3, -6, 7, -3, 2, -19, 24] | |
map (negate . abs) [5, -3, -6, 7, -3, 2, -19, 24] | |
map (\xs -> negate (sum (tail xs))) [[1..5], [3..6], [1..7]] | |
map (negate . sum . tail) [[1..5], [3..6], [1..7]] | |
sum (replicate 5 (max 6.7 8.9)) | |
sum . replicate 5 $ max 6.7 8.9 | |
replicate 2 (product (map (+3) (zipWith max [1,2] [4,5]))) | |
replicate 2 . product . map (+3) $ zipWith max [1,2] [4,5] | |
sum (takeWhile (<10000) (filter odd (map (^2) [1..]))) | |
sum . takeWhile (<10000) . filter odd $ map (^2) [1..] |
Thanks! I practiced how to shorten my code with the function composition and function application.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
теперь я понимаю, что имели ввиду, когда рассказывали про китайский код :)