Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Elixirだ 第1回 - 基礎だ -

6,305 views

Published on

GMOペパボ社内、第1回Elixir勉強会の資料

Published in: Engineering
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Visit Here to Read PDF eBook === http://pdfuhuijuiuiuo.ygto.com/B07DKNBSTG-bewitched-by-the-darkness-tome-1-elixir-of-crypt.html
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❤❤❤ http://bit.ly/2F90ZZC ❤❤❤
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2F90ZZC ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Elixirだ 第1回 - 基礎だ -

  1. 1. 第1回 - 基礎だ - GMO Pepabo, Inc. Joe Honzawa 2015/4/30 Elixir勉強会 Elixirだ
  2. 2. Elixirとは > Erlang VM上で動く関数型言語 > 並列分散 > 高可用性 > 動的型付け > モダンな文法 > マクロでメタプログラミング > プロトコル
  3. 3. Elixirをつくった人 > José Valim > 歩く生産性 > rackやrailsにもコミット
  4. 4. Rubyistの皆さんが 入りやすそうなとこから
  5. 5. Install > $ brew install elixir
  6. 6. IEx > $ iex
  7. 7.
  8. 8. Types(?) > integer > float > atom > boolean > binary > string > list > tuple > map > range > function など
  9. 9. Integer > 10 > 0b101 > 0o12 > 0x0a
  10. 10. Float > 1.0 > 3.14 > 6.02e23 > 1.602e-19 > 1e3 ← これダメ
  11. 11. Atom > Rubyで言うSymbol > :atom > :hello > :’white spaces !?’ > nil == :nil
  12. 12. Boolean > true > false > 実はatom > :true > :false
  13. 13. Binary > <<1>> > <<256>> == <<0>> > <<1>> == <<1::size(8)>> > <<1, 0>> == <<256::size(16)>> > <<1::float>> == <<63,240,0,0,0,0,0,0>>
  14. 14. String > “hello world” > “世界を征服だ” > 必ずダブルクォートしてー > “hey” == <<104,101,121>> > ‘hey’ == [104,101,121]
  15. 15. List > 単方向リスト > [1, 2, 3] > [true, [1, 2, 3], “hey”] > [1 | [2, 3]] == [1, 2, 3] > [1, 2 | []] == [1, 2] > 先頭への要素追加は高速
  16. 16. Tuple > 値の組 > {:ok, 30} > {1, 2, 3, 4, 5} > ランダムアクセスはO(1) > 更新や追加はコスト高
  17. 17. Map > %{} > %{“price”=> 3980} > map = %{price: 100, amount: 2} > map.price > Map.get(map, :price) > map = Map.put(map, :amount, 1)
  18. 18. Range > 範囲 > 1..3 > 4..-5 > 1.2 .. 3.8 > (1.5 in 1.2 .. 3.8) == true
  19. 19. Function > 無名関数 > fn (x, y) -> x * y end > fun = &(&1 * &2) > fun.(3, 4) == 12 > 定義済み関数のキャプチャ > IOモジュールのputs関数(arity: 1) > Enum.each([1, 2], &IO.puts/1)
  20. 20. 制御構文
  21. 21. case case the_number do 1 -> “one” 2 -> “two” 3 -> “three” end
  22. 22. if if now == :morning do “good morning” else “hi” end
  23. 23. cond cond do rem(y, 400) == 0 -> “Yes” rem(y, 100) == 0 -> “No” rem(y, 4) == 0 -> “Yes” true -> “No” end
  24. 24. 無いもの > return > 最後の評価値が返る > loop, while > 再帰で
  25. 25. パターンマッチ
  26. 26. 賢く束縛 > [x, y] = [1, 2] > x == 1 > y == 2 > {1, x, 3} = {1, 2, 3} > x == 2
  27. 27. アンスコ > 使わない変数の頭につける > 何にでもマッチ > 値は要らない > [head | _] = [1, 2, 3] > {y, _m, _d} = {2015, 4, 30}
  28. 28. 代表的な > {:ok, res} = File.read “a.txt” > [head | tail] = [1, 2, 3, 4] > head == 1 > tail == [2, 3, 4]
  29. 29. 実際的な case File.read(“a.txt”) do {:ok, res} -> res {:error, :enoent} -> “oh it isn’t here” {:error, :eacces} -> “you can’t read it” _ -> “?” end
  30. 30. MatchError > {:ok, res} = File.read “a.txt” > File.read/1 > {:ok, content} > {:error, reason} > (MatchError) no match of right hand side value: {:error, :enoent}
  31. 31. ピン止め > x = 1 > [^x, y, 3] = [1, 2, 3] > y = 2 > [^x, y, 3] = [5, 4, 3] > MatchError
  32. 32. モジュールと関数
  33. 33. def defmodule MyModule do def print(arg) do iikanjini_hyoji(arg) end defp iikanjini_hyoji(arg) do IO.inspect arg end end MyModule.print %{price: 298}
  34. 34. 原則 > あらゆる関数はモジュールに属する > 名前かarityが違うなら別の関数 > sum/1とsum/2は別物
  35. 35. 重要なスライドです defmodule MyModule.Math do def sum(list), do: sum(list, 0) defp sum([], acc), do: acc defp sum([h|t], acc) do sum(t, h+acc) end end
  36. 36. 慣習 > ワーカ関数の名前はdo_xxx > モジュール名とファイル構造は対応させる > lib/my_module/math.ex > MyModule.Math > 最も関心のあるものを第一引数に > 例外を投げる関数の名前はxxx! > 真偽値を返す関数の名前はxxx?
  37. 37. デフォルト引数 defmodule MyModule do def say(word “hi”) do IO.puts word end end MyModule.say(“hello”) MyModule.say
  38. 38. ガード式 defmodule MyModule do def sum(list) when is_list(list) do sum(list, 0) end # 略 end !! ガード式で使える関数は限られている !!
  39. 39. ガードで使える奴ら > == > != > === > !== > > > < > <= > >= > and > or > not > ! > + > - > * > / > <> (左辺がリテラル) > ++ (左辺がリテラル) > in > is_atom/1 > is_binary/1 > is_bitstring/1 > is_boolean/1 > is_float/1 > is_function/1 > is_function/2 > is_integer/1 > is_list/1 > is_map/1 > is_nil/1 > is_number/1 > is_pid/1 > is_port/1 > is_reference/1 > is_tuple/1 > abs/1 > bit_size/1 > byte_size/1 > div/2 > elem2 > hd/1 > length/1 > map_size/1 > node/0 > node/1 > rem/2 > round/1 > self/0 > tl/1 > trunc/1 > tuple_size/1
  40. 40. directives defmodule MyModule do import Enum alias Enum, as: E require Integer use ExUnit end
  41. 41. import defmodule MyModule do import Enum, only: [count: 1] def kazoeru(list) do count(list) # Enum.count/1 end end MyModule.kazoeru [1, 2, 3] MyModule.count [1, 2] → ❌
  42. 42. alias defmodule MyModule do alias Enum, as: E def kazoeru(list) do E.count(list) # Enum.count/1 end end MyModule.kazoeru [1, 2, 3]
  43. 43. as無しalias defmodule MyModule do alias Phoenix.HTML.Form alias Phoenix.HTML.Form, as: Form # 等価 end
  44. 44. requireとuse また後で…
  45. 45. エコシステム
  46. 46. Mix > Rubyにおけるbundlerとrake > 依存性解決 > タスクランナー > mix new my_app > mix test > mix something.i.defined
  47. 47. Hex > Rubyにおけるrubygems > パッケージマネージャ > https://hex.pm > ErlangのライブラリもOK > ファイル構成見てよしなにシュッと
  48. 48. Hex on Heroku
  49. 49. はじめての Elixirプロジェクト
  50. 50. $ mix new please $ cd ./please $ ls
  51. 51. Mix project > lib/please.ex > test/ > please_test.exs > test_helper.exs > config/config.exs > mix.exs
  52. 52. lib/please.ex defmodule Please do def give_me(:sushi), do: “🍣” def give_me(:beer), do: “🍺” def give_me(_other), do: “❓” end
  53. 53. $ iex -S mix iex(1)> Please.give_me :sushi “🍣”
  54. 54. 余談 > BEAMファイル > バイトコード > JavaでいうClassファイル > _build/の奥のほう > Elixir.Please.beam
  55. 55. テスト書きましょ
  56. 56. テストライブラリ > ExUnit > とりあえずこれ覚えるべき > ShouldI > Bruce Tateさん作 > One Experiment, Multiple Measurements > 中身はExUnit > ESpec
  57. 57. test/please_test.exs defmodule PleaseTest do use ExUnit.Case alias Please, as: Plz test “sushi” do assert Plz.give_me(:sushi) == ”🍣” end test “neither sushi nor beer” do assert Plz.give_me(:hoge) == ”❓” end end
  58. 58. $ mix test
  59. 59. Redも見ておきましょう defmodule PleaseTest do use ExUnit.Case alias Please, as: Plz test “sushi” do assert Plz.give_me(:sushi) == ”🍕” end test “neither sushi nor beer” do assert Plz.give_me(:hoge) == ”❓” end end
  60. 60. ワンダーである
  61. 61. やったこと > Elixirのインストール > 型 > 制御構文case, if, cond > パターンマッチ > モジュール、関数、ディレクティブ > MixとHex > Mixプロジェクトの作成とテスト

×