1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その340

Posted at

概要

paiza.ioでelixirやってみた。
thenとtapに、なじめないので、訓練してみた。

サンプルコード


#then/2は第1引数の値を第2引数の関数に渡し、その結果を返します。
#tap/2は第1引数の値を第2引数の関数に渡して実行しますが、第1引数に渡した値自体をそのまま返します。

then(5, &IO.puts(&1))
|> IO.inspect
IO.puts("ok0")

tap(5, &IO.puts(&1))
|> IO.inspect
IO.puts("ok1")

tap(1, fn x -> 
    x + 1 
end)
|> IO.inspect
IO.puts("ok2")

then(2, fn x -> 
    x + 2 
end)
|> IO.inspect
IO.puts("ok3")


then(5, fn x -> 
    x + 1
end)
|> IO.inspect()

tap(3, fn x -> 
    x + 1 
end)
|> IO.inspect()


"hello world"
|> tap(&IO.puts/1)
|> then(&Regex.scan(~r/\w+/, &1))


"hello world"
|> (fn x ->
      IO.puts(x)
      x
    end).()
|> (&Regex.scan(~r/\w+/, &1)).()




実行結果

5
:ok
ok0
5
5
ok1
1
ok2
4
ok3
6
3
hello world
hello world

成果物

以上。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?