Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Elixir Functions returns Functions

More than 5 years have passed since last update.

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
tbpgr
Rubyを扱う人事(研修開発、エンジニア採用) Learning Designer。 tbpgr の読み方は(てぃーびー) 個人ブログでも色々と情報を垂れ流してます。 http://tbpgr.hatenablog.com/
http://tbpgr.hatenablog.com/
studist
「伝えることを、もっと簡単に」をミッションにビジュアルSOPマネジメントプラットフォームのBtoB SaaS「Teachme Biz」を開発・運営するスタートアップ
https://medium.com/studist-dev
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away