LoginSignup
9
5

More than 5 years have passed since last update.

HaskellでElixirのようなパイプラインで記述したいとき

Last updated at Posted at 2016-10-20

関数合成の本来の目的は置いておいて、関数合成の記述よりElixirのパイプラインの記述の方が分かりやすい気がしたので。

【関数合成の記述】

someFunc :: IO ()
someFunc = do
  let a = sum . take 5 . reverse . map (*3) $ [1..10]
  print a

【パイプラインの記述】

someFunc :: IO ()
someFunc = do
  let a = [1..10]
          |> map (*3)
          |> reverse
          |> take 5
          |> sum
  print a

infixl 0 |>
(|>) :: a -> (a -> b) -> b
(|>) = flip ($)
--a |> f = f a

勉強会では関数合成の記述は英語の順序で、パイプラインの記述は日本語の順序だから、日本人にはパイプラインの方が馴染みやすいのではという意見も。。。

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5