LoginSignup
0
0

More than 5 years have passed since last update.

Elixir Functions returns Functions

Posted at

Elixir Functions returns Functions

概要

Elixir の Functions から Functions の返却について。

サンプル

2つの数値を合計して、基数を指定して返却する関数を返却する
関数を作成します。

sum_to_s_f = fn (base) -> 
  fn (a, b) ->
     Integer.to_string(a + b, base)
  end
end
IO.puts sum_to_s_f.(10).(10, 6)
IO.puts sum_to_s_f.(2).(10, 6)
IO.puts sum_to_s_f.(8).(10, 6)
IO.puts sum_to_s_f.(16).(10, 6)
IO.puts sum_to_s_f.(36).(10, 6)
  • 出力
16
10000
20
10
G
0
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
0
0