Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir ご紹介

Naoya Ito
August 25, 2015

Elixir ご紹介

Shibuya.ex #1 での発表資料です

Naoya Ito

August 25, 2015
Tweet

More Decks by Naoya Ito

Other Decks in Technology

Transcript

  1. &MJYJS͝঺հ
    /BPZB*UP
    ,BJ[FO1MBUGPSN *OD

    4IJCVZBFY

    View full-size slide

  2. ͜Μʹͪ͸ɺ࢒೦ͳ
    ೔ຊͷ8FCٕज़ऀͰ͢

    View full-size slide

  3. ΞδΣϯμ
    •  ࿩͢͜ͱ
    – &MJYJSͷͬ͘͟Γಛ௃
    – ݴޠతͳػೳ
    – 051पΓͷ֓ཁ
    •  ࿩͞ͳ͍͜ͱ
    – ࡉ͔͍γϯλοΫεŋŋŋࢀߟࢿྉΛͲ͏ͧ

    View full-size slide

  4. &MJYJSɺͬ͘͟Γಛ௃

    View full-size slide

  5. &MJYJS
    •  &SMBOH7.ͷ্Ͱಈ͘
    •  ಈతܕ෇͚ͳؔ਺ܕݴޠ
    •  ͜ͳΕͨύοέʔδ؅ཧγεςϜ.JY
    •  ܰྔϓϩηεɺΞΫλʔʹΑΔฒߦॲཧ
    •  051

    View full-size slide

  6. 3VCZ
    •  Ұݟ͢Δͱ3VCZͬΆ͍
    •  ࣮ࡍͦΕ΄Ͳ3VCZͬΆ͘ͳ͍
    •  Ή͠Ζ&SMBOH051
    – γϯλοΫε͕ೃછΈ΍͍͢&SMBOH051
    ͱଊ͑ͨ΄͏͕ྑ͍

    View full-size slide

  7. ͳͥ&MJYJS
    •  ϥϯλΠϜ͕ڧྗ
    – ΞΫλʔϞσϧʹΑΔฒߦॲཧج൫Λݴޠ
    ϥϯλΠϜͰඪ४౥ࡌ
    ͱ͍͏Θ͚Ͱɺॏཁͳͷ͸
    3VCZΈ͍ͨdͰ͸ͳ͘ɺ
    &SMBOH051ͷ্ʹ৐ͬͯ
    Δͬͯͱ͜

    View full-size slide

  8. ؔ਺ܕݴޠͱͯ͠ͷ&MJYJS

    View full-size slide

  9. ಈతܕ෇͚ͷؔ਺ܕݴޠ

    View full-size slide

  10. ؔ਺ܕݴޠͱͯ͠ͷ&MJYJS
    •  ୈҰڃؔ਺ɺߴ֊ؔ਺
    •  ύλʔϯϚον
    •  ෆมͳσʔλܕ
    •  ࠶ؼ ຤ඌݺͼग़͠࠷దԽ͋Γ

    View full-size slide

  11. ͳ͍΋ͷ
    •  Ͱ͸
    ͳ͍
    – ੩తܕ෇͚
    – ७ਮؔ਺ܕ ෭࡞༻͋Γ

    – ෦෼ద༻ΧϦʔԽ
    – 0QUJPOܕ .BZCF

    •  ͋ΔΑ
    – Ϧετ಺แදه
    – ஗ԆධՁɺແݶϦετ ˞ݴޠશମͰ͸ͳ͍

    View full-size slide

  12. ύλʔϯϚον
    •  &MJYJSͷจ๏ͷجૅʹͳͬͯΔػೳ
    – ؔ਺ܕݴޠͰ͸݁ߏΈΔŋŋŋ)BTLFMMͱ͔
    – JGจͳͲΛ࢖Θͳ͍એݴతͳهड़ʹߩݙ
    •  ஋ͷύλʔϯΛهड़͠ɺ஋ͱর߹͢Δ
    – ύλʔϯͱ஋͕Ϛονͨ͠ΒɺԿ͕͔͕͠ߦ
    ΘΕΔ
    – ͸࣮͸ύλʔϯϚονԋࢉࢠ

    View full-size slide

  13. ύλʔϯϚον
    h"p://www.slideshare.net/Joe_noh/elixir-­‐01

    View full-size slide

  14. ύλʔϯϚον
    εςʔλείʔυͷ
    ͱ͖͚ͩؔ਺͕ݺ͹ΕΔ
    ஋͕͜ͷߏ଄ΛؚΉͱ͖͚ͩ
    ݺ͹ΕΔɻ·ͨɺߏ଄಺ͷ஋
    ͕XFBUIFSม਺Λଋറ

    View full-size slide

  15. ύλʔϯϚον࠶ؼ
    Ϧετ͕ۭͷͱ͖
    ఀࢭ৚݅

    Ϧετͷઌ಄ཁૉ͕@IFBE
    Λଋറɺ࢒Γ͕UBJMΛଋറ

    View full-size slide

  16. ύλʔϯϚονͷϢʔεέʔε
    •  ม਺ଋറ
    •  σʔλߏ଄ͷ෼ղ
    •  Ϧετॲཧ X࠶ؼ

    •  DBTFจ
    •  ύλʔϯຖͷؔ਺ఆٛ
    – ஋ʹΑΔؔ਺ͷબ୒

    View full-size slide

  17. cŋŋŋύΠϓϥΠϯԋࢉࢠ
    ؔ਺ͷ໭Γ஋Λɺ࣍ͷୈҰҾ਺ʹ౉͢ɻ
    'ΠϯεύΠΞΒ͍͠

    ؔ਺Λܨ͛ͯॻ͚ͯ
    ؾ͍͍࣋ͪ

    View full-size slide

  18. খ͞ͳؔ਺ΛύΠϓϥΠϯ
    Ͱܨ͍͛ͯ͘ͷ͕&MJYJSྲྀ
    ͏ʔΉɺ.BZCFཉ͍͠ŋŋŋ

    View full-size slide

  19. ෆมͳσʔλܕ
    •  σʔλܕ͸ෆม
    – 4USJOH -JTU 5VQMF .BQ )BTI%JDU
    )BTI4FU
    •  ཁ͢Δʹഁյతૢ࡞͕ෆՄೳ͚ͬͯͩ
    •  dict2  =  Dict.put(dict,  :foo,  3)  
    – dict  ͸ෆมɺߋ৽͞Εͨ  dict2

    View full-size slide

  20. GPS XIJMF͕ͳ͍
    •  ࠶ؼΛ࢖͏͔ ຤ඌݺͼग़͠࠷దԽ


    •  ͞΋ͳ͘͹ϧʔΫɺ&OVNΛ࢖͑
    iex>  [1,2,3]  |>  Enum.each  fn(x)  -­‐>  IO.puts(x)  end  
    1  
    2  
    3  
    :ok  
     
    iex>  [1,2,3]  |>  Enum.reduce(0,  fn(x,  acc)  -­‐>  x  +  acc  end)  
    6

    View full-size slide

  21. Ϧετ಺แදه
    •  )BTLFMM౳Ͱ͓ͳ͡Έͷ
    – [x  |  x  <-­‐  xs,  x  <  p]  
     
    •  &MJYJSͰ͸
    – for  x  <-­‐  xs,  x  <  p,  do:  x  
    ਖ਼௚͜Εʹؔͯ͠͸
    &SMBOHͦͷ··Ͱྑ͔ͬ
    ͨͷͰ͸ŋŋŋ ݸਓͷײ૝

    View full-size slide

  22. ϐλΰϥε਺Λ୳͢
    "#$
    Λຬͨ͢" # $ͷ੔਺ͷ
    ૊Λݟ͚ͭΔ

    View full-size slide

  23. 4USFBN
    •  ߹੒ՄೳͰ஗ԆධՁͳ&OVNFSBCMFT
    – &OVN͸(SFFEZ
    – 4USFBN͸-B[Z
    •  ແݶϦετ΍஗ԆධՁ͕ཉ͍͠ͱ͖͸͜
    Ε

    View full-size slide

  24. 3BOHFΛ4USFBNʹม׵ɺ
    ύΠϓϥΠϯԋࢉࢠͰ
    pMUFSͱNBQΛ߹੒
    UBLF
    ͨ͠ͱ͜ΖͰॳΊͯ
    ධՁˠ݅ͷΈܭࢉ
    ஗ԆධՁ

    View full-size slide

  25. ϑΟϘφονετϦʔϜ
    4USFBNVOGPME͸ΞΩϡϜ
    Ϩʔλʹܭࢉ݁ՌΛੵΜͰ࠶
    ؼతʹؔ਺Λద༻
    &OVNUBLF
    ͨ͠ͱ͜Ζ
    ͰॳΊͯܭࢉ

    View full-size slide

  26. ϙϦϞʔϑΟζϜ
    •  ϙϦϞʔϑΟζϜͷ࣮ݱ
    – +BWBŋŋŋΠϯλϑΣʔεͳͲͷ্ҐͷܕͰ
    – 3VCZŋŋŋμοΫλϐϯάͰ
    – )BTLFMMŋŋŋଟ૬ܕͰ
    – &MJYJSŋŋŋϓϩτίϧͰ

    View full-size slide

  27. ϓϩτίϧ
    ҟͳΔσʔλܕʹಉ໊͡લ
    ͷؔ਺Λద༻ɻܕʹԠͯ͡
    ৼΔ෣͍͕มΘΔ

    View full-size slide

  28. ϓϩτίϧͷྑ͍ར༻ྫ
    h"p://blog.drewolson.org/building-­‐an-­‐elixir-­‐web-­‐app/

    View full-size slide

  29. &MJYJSΒ͍͠ίʔυ
    •  ύλʔϯϚονΛੵۃతʹ࢖͏
    •  ෭࡞༻͸ՄೳͳΒආ͚Δ෼཭
    •  &OVN౳ͷؔ਺Λ૊Έ߹Θͤͯએݴతʹ
    ॻ͘
    •  ύΠϓϥΠϯԋࢉࢠ|>  ࢖͍୯Ұͷ໾ׂ
    ͷখ͞ͳؔ਺Λܨ͛Δ  

    View full-size slide

  30. &SMBOH051ͱ&MJYJS

    View full-size slide

  31. &SMBOH7.ͷ্Ͱಈ͘
    BEAM  (Erlang  VM)
    OTP
    Elixir

    View full-size slide

  32. ܰྔϓϩηε
    •  &SMBOH7.಺ͷ࣮ߦίϯςΩετͷ୯Ґ
    – 04ͷϓϩηεͰ͸ͳ͍
    •  ϓϩηεϫʔυఔ౓ɻ௒ܰྔ
    – ϊʔυ಺Ͱ਺ඦʙ਺ઍϓϩηεͱ͔ฏؾͰ
    ࢖͍·͘Δ
    –  ϓϩηεͰʙͱ͔ͦ͏͍͏࿩΋ฉ
    ͘

    View full-size slide

  33. ܰྔϓϩηεͱฒߦ
    •  ܰྔϓϩηε͸7.ͰεέδϡʔϦϯά
    ͞Ε࣮ͯߦ͞ΕΔ
    •  7.͸εϨουϓʔϧ ͔֬
    Ͱ࣮૷͞Ε
    ͍ͯΔ
    – ܰྔϓϩηεͰͷฒߦॲཧ͸ϚϧνίΞͰΛ
    ࢖͑Δ

    View full-size slide

  34. ΞΫλʔϞσϧ
    •  ϓϩηεؒ௨৴͸ϝοηʔδύογϯά
    – ϓϩηεͷதʹʮϝʔϧϘοΫεʯ
    •  ͦ͜ʹϝοηʔδΛૹΔ TFOE

    •  ϝοηʔδʹ͸೚ҙͷ஋Λఴ෇Մ
    – ϓϩηε͸ͦΕΛड৴଴ͪ SFDFJWF

    – ஋͸ඞͣίϐʔ͞ΕΔ ڞ༗͞Εͳ͍

    •  σʔλΛڞ༗͠ͳ͍㱺ϩοΫ͕͍Βͳ͍

    View full-size slide

  35. ΞΫλʔϞσϧ

    View full-size slide

  36. 051
    •  ϓϩηεपΓͷඪ४ϥΠϒϥϦϑϨʔϜ
    ϫʔΫ܈
    •  &SMBOHͷ࠷େͷࢿ࢈
    – ΞΫλʔϞσϧ&SMBOH051͸ͳͲଞݴ
    ޠ΁େ͖ͳӨڹΛ༩͍͑ͯΔ
    •  ྫ4DBMBͷ"LLB

    View full-size slide

  37. 051ϏϔΠϏΞ (FO4FSWFS

    ܰྔϓϩηεʹύλʔϯ
    ϏϔΠϏΞ
    ʹ৐͔ͬΔ
    ͚ͩͰαʔόΛ࡞ΕΔɻ
    ཁ͸ϑϨʔϜϫʔΫ

    View full-size slide

  38. BTZODBXBJUͷཪͰ͸Ξ
    Ϋλʔ͕ॲཧΛฒྻԽ͢
    Δ
    051ϏϔΠϏΞ 5BTL

    View full-size slide

  39. 4VQFSWJTPS
    Supervisor
    use  
    GenServer  
    ؂ࢹ
    ʮಥવͷࢮʂʯ
    ϓϩηεࢮΜͩ͠ɺઓུ
    ʹ߹Θͤͯ࠶ىಈ͠ͱ͘
    Θ
    crash

    View full-size slide

  40. -FUJUDSBTI
    •  ࣦഊʹඋ͑ͳ͍ɻྫ֎Λั·͑ͳ͍
    •  4VQFSWJTPSͰ؂ࢹ͓͍ͯͯ͠ɺͦͷ·
    ·ى͜͢ͳΓύϥϝʔλม͑ͯϦτϥΠ͞
    ͤΔͳΓŋŋŋ

    View full-size slide

  41. 4VQFSWJTJPO5SFF
    h"p://qiita.com/naoya@github/items/ad18b49e9ed56a72cab6

    View full-size slide

  42. ޠΓ͔͕ͨͬͨଟ෼͕࣌ؒͳ͍ʂ
    •  ܰྔϓϩηε͸γεςϜͷ৭ΜͳσβΠϯ
    ͱ૬৐ޮՌΛಇ͔͍ͤͯΔΑ
    – ύλʔϯϚονͰએݴతʹؔ਺Λબ୒͢Δ͜
    ͱͱ-FUJUDSBTI͸૬ੑ͕ྑ͍Α
    – ϓϩηεͷΞυϨε͸ಁաੑ͕͋ͬͯɺଞͷ
    ϊʔυ΁ͷϝοηʔδύογϯά΋ҰॹͩΑ
    ˠ؆୯ʹεέʔϧ͢ΔΑ
    – ܰྔϓϩηε୯ҐͰ($͢Δ͔ΒϝϞϦ͍Β
    ͳ͘ͳͬͨΒϓϩηε͝ͱࣺͯΕ͹ྑ͍Α

    View full-size slide

  43. 3FBDUJWF
    3FBDUJWF.BOJGFTUP ϦΞΫςΟϒએݴ

    h"p://www.reacUvemanifesto.org/ja

    View full-size slide

  44. ΞΫλʔʹΑΔ
    ϝοηʔδύογϯά

    View full-size slide

  45. 4VQFSWJTJPO5SFF
    -FUJUDSBTI

    View full-size slide

  46. ܰྔϓϩηεͷ
    ΞυϨεಁաੑ

    View full-size slide

  47. &SMBOHͱͷ૬ޓޓ׵ੑ
    •  &SMBOHͱ&MJYJS͸૬ޓޓ׵
    – &SMBOHͷϥΠϒϥϦΛ&MJYJSͰ࢖͑Δ
    – &MJYJSͷΛ&SMBOHͰ΋࢖͑Δ

    View full-size slide

  48. .JY)FY
    •  Ϗϧυπʔϧύοέʔδ؅ཧ
    – 3VCZͷ#VOEMFSSVCZHFNT
    – /PEFKTͷOQN

    View full-size slide

  49. IDDBXFTPNFFMJYJS
    •  ϥΠϒϥϦͷϦϯΫू

    View full-size slide

  50. %JBMZ[FS
    ιʔεʹܕ৘ใΛΞϊςʔ
    γϣϯ͠ͱ͘ͱ
    ੩తܕνΣοΫ͸Ͱ͖Δ

    View full-size slide

  51. &MJYJSೖ໳ιʔε ೔ຊޠ

    •  8FC%#13&44WPM
    –  IUUQHJIZPKQNBHB[JOFXEQSFTTBSDIJWFWPM

    •  +PF@OPI͞ΜͷεϥΠυू
    –  IUUQXXXTMJEFTIBSFOFU+PF@OPIQSFTFOUBUJPOT
    •  (FUUJOH4UBSUFEͷ຋༁
    –  IUUQFMJYJSKBTFOBOFUXPSLTHFUUJOH@TUBSUFEIUNM
    •  2JJUBr&MJYJS
    –  IUUQTRJJUBDPNUBHTFMJYJS

    View full-size slide

  52. &MJYJSຊ͓͢͢Ί

    View full-size slide

  53. ·ͱΊ
    •  &MJYJS͸&SMBOH051ͱζο༑
    •  ಈతܕ෇͚ͷؔ਺ܕݴޠ
    – ͱɺݴͬͯ΋ා͘ͳ͍
    – ύλʔϯϚονɺύΠϓϥΠϯԋࢉࢠɺ
    &OVN4USFBN
    •  051ͰΞΫλʔͳฒߦॲཧ
    •  -FUJUDSBTI

    View full-size slide