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

猫とたはむれる

 猫とたはむれる

ScalaのFP用ライブラリ cats の紹介です。

8f4860855bc98d47af58e43652aae1e7?s=128

cedretaber

May 15, 2017
Tweet

More Decks by cedretaber

Other Decks in Programming

Transcript

  1. ೣͱͨ͸ΉΕΔ @cedretaber

  2. Twitter / Github @cedretaber ͓࢓ࣄ Scala TypeScript झຯ Ruby Erlang

    / Elixir F# Dݴޠ
  3. cats ࠓճ͝঺հ͢Δͷ͸typelevel / cats 4DBMBͰ'1Λߦ͏ҝͷϥΠϒϥϦ 4DBMB[ͱ͔ͷϑϨϯζ

  4. Why cats? ࢖͍΍͍͢σʔλܕ͕ ἧ͍ͬͯΔ 4DBMBඪ४ͷσʔλܕʹ ΋ศརͳؔ਺Λ஫ೖ͠ ͯ͘ΕΔ ιʔε͕ಡΈ΍͘͢ݟ ָ͍͍ͯͯ͠

  5. NonEmptyList

  6. ʮઈରʹۭ͡Όͳ͍ࣄ͕อূ͞ΕͨʯϦετɻ ʮ͜͜Ͱ౉ͬͯ͘ΔϦετ͸ۭ͡Όͳ͍ʯͬͯ࣌ʹ ࢖͏ɻ

  7. None
  8. Ϧετͱͷ૬ޓม׵ /PO&NQUZ-JTUΛ࢖͍͍ͨ৔໘͸-JTUΛ࢖͍͍ͨ৔ ໘ʹแؚ͞Ε͍ͯΔ͸ͣͳͷͰɺϦετͱͷ૬ޓม ׵͸ଟ༻͢Δɻ

  9. None
  10. ͦͷଞͷϝιου /PO&NQUZ-JTU͸ී௨ͷϦετͷϝιου͕֓Ͷ࣮ ૷͞Ε͍ͯΔɻ ·ͨɺ4FNJHSPVQ,ɺ5SBWFSTFɺ.POBEͳͲͷΠ ϯελϯεͳͷͰɺศརͳϝιου΋਺ଟ͘࢖͑Δ ʢۭͷঢ়ଶ͕ଘࡏ͠ͳ͍ͨΊɺϞϊΠυͰ͸ͳ͘൒ ܈ͳͷͰ஫ҙɻʣ

  11. None
  12. None
  13. None
  14. ෇ه NonEmptyVector NonEmptyStream ΋͋Δɻ

  15. Validated

  16. ʮ-FGUΛ஝ੵ͢Δ&JUIFSʯ ໊લͷ௨ΓɺόϦσʔγϣϯΛ͔͚Δ࣌౳ʹॏๅ͢ Δɻ

  17. ྫ Ϣʔβొ࿥ͷॲཧΛߟ͑Δɻ Ϣʔβ*%͸ॏෳෆՄɺύεϫʔυ͸จࣈҎ্ɺΈ ͍ͨͳͷ৚͕݅͋Δͱ͢Δɻ

  18. None
  19. ͜ͷ࣮૷ͩͱɺ*%ͱύεϫʔυͷ྆ํʹ໰୊͕͋Δ ৔߹΋*%ͷΤϥʔ͔͠ฦΒͳ͍ɻ όϦσʔγϣϯΛߦ͏৔߹ɺೖྗʹଘࡏ͢Δશͯͷ ϛεΛฦ͢ํ͕Ϣʔβʹ༏͍͠ɻ ͳͷͰɺ7BMJEBUFEΛ࢖͏ɻ

  20. None
  21. None
  22. /PO&NQUZ-JTUͱͷซ༻ ઌड़ͷྫͩͱ4USJOHΛ࢖ͬͯΤϥʔΛ஝ੵ͕ͨ͠ɺ จࣈྻΛͪ͝Όͪ͝Όͱ઀ଓͯ͠͠·͏ͷ͸͋·Γ ៉ྷͳ΍Γํͱ͸ݴ͑ͳ͍ɻ ͳͷͰɺ/PO&NQUZ-JTUΛ࢖ͬͯ஝ੵͯ͠ΈΔɻ

  23. Ͳ͏ͯ͠/PO&NQUZ-JTUͳͷ͔ʁ ผʹ௨ৗͷ-JTUͰ΋ྑ͍ͷ͕ͩɺ7BMJEBUFEͷ৔߹ɺ *OWBMJEʹͳΔ࣌͸ԿΒ͔ͷ஋͕ೖ͍ͬͯΔ͸ͣͳͷ Ͱɺ*OWBMJE͔ͭத਎͕ۭͱ͍͏ࣄ͸͋Γ͑ͳ͍ɻ ͳͷͰɺ/PO&NQUZ-JTUͷํ͕૬Ԡ͍͠ɻ

  24. None
  25. 7BMJEBUFE /PO&NQUZ-JTUͷ૊Έ߹Θͤ͸ඇৗʹ Α͘࢖͏ͷͰɺDBUTʹ͸*OWBMJEΛ/PO&NQUZ-JTU ͱ૝ఆͨ͠7BMJEBUFE/FMͱ͍͏ܕ͕༧Ί༻ҙ͞Ε ͍ͯΔɻ ˣఆٛ

  26. None
  27. ෇ه ʮਖ਼͍͠஋Λฦͭͭ͠ɺ ్தܦաͷԿ͔΋஝ੵ ͍ͨ͠ʯͱ͍͏৔߹͸ Iorͱ͍͏σʔλܕ͕࢖ ͑Δɻ

  28. List, Either

  29. ҉໧ͷม׵Λར༻ͯ͠ɺDBUT͸طଘͷΫϥεʹ΋৭ʑ ͳϝιουΛੜ΍ͯ͘͠ΕΔɻ ಛʹɺ-JTU΍&JUIFSͷ֦ு͕ศརɻ 5SBWFSTF΍'PMEBCMF͸Ͳ͜·Ͱ΋ศརɻ YҎલͳΒ&JUIFSʹNBQqBU.BQΛੜ΍ͯ͠ ͘ΕΔͷ΋ศརɻ

  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. 6OBQQMZʹ͍ͭͯ ্Ͱ&JUIFS΍7BMJEBUFEͷ-JTUʹTFRVFODF΍ USBWFSTFΛద༻͍ͯ͠ΔͷΛݟͯɺٙ໰ʹײͨ͡ํ ΋ଟ͍ͩΖ͏ɻ ͱ͍͏ͷ΋ɺ෦෼ద༻͞ΕͨܕҾ਺Λਪ࿦Ͱ͖ͳ͍ ͱ͍͏໰୊ʢ4*ʣ͸༗໊ͰɺͦΕʹରԠ͢Δ ͨΊʹDBUT͸6OBQQMZΛ࢖͍͔ͬͯͨΒͩɻ

  37. None
  38. ͔͜͠͠ͷ໰୊͸೥ఔલʹղܾ͞Ε͓ͯΓɺ 4DBMB͔Β͸ܕਪ࿦͕վળ͞Ε͍ͯΔɻ ·ͨچόʔδϣϯͷ4DBMBͰ΋ɺTCUͷϓϥάΠϯΛ ࢖͏ࣄͰಉ౳ͷػೳΛར༻Ͱ͖Δɻ ͜ΕΛड͚ͯDBUTͰ͸ɺٞ࿦ͷ຤ɺ6OBQQMZͷར ༻Λίʔυ͔Βഉআ͢Δࣄʹͨ͠Β͍͠ɻ

  39. ऴΘΓʹ

  40. DBUT΍TDBMB[ʹ༻ҙ͞Εͨศརͳؔ਺Λ࢖͏ͱɺ΍ ΍͍͜͠ॲཧΛεοΩϦͱॻ͘ࣄ͕Ͱ͖Δɻ ಛʹUSBWFSTF΍TFRVFODFͳͲ͸ɺ࠶ؼؔ਺΍ GPME-FGUΛۦ࢖ͯ͠ॻ͜͏ͱ͢ΔͱͲ͏ͯ͠΋ෳࡶ ʹͳͬͯ͠·͏ɻ

  41. ͨͩ͠ɺແҋʹ࢖͑͹͍͍ͱ͍͏Θ͚Ͱ΋ͳ͍ͷͰ ஫ҙɻ ݟ׳Εͳ͍ϝιουΛ࢖͏ΑΓɺ࠶ؼؔ਺ͱ GPME-FGUͰॻ͍ͨํ͕ʢिؒޙͷࣗ෼ΛؚΊͨʣ ଞਓʹͱͬͯಡΈ΍͍͢ࣄ΋͋Δɻ ͦͷ͋ͨΓ͸νʔϜͷ܏޲ͳͲݟͭͭௐ੔͍͖ͯ͠ ·͠ΐ͏ɻ

  42. ࢀߟࢿྉ w UZQFMFWFMDBUT IUUQTHJUIVCDPNUZQFMFWFMDBUT w ೣ൪ IUUQFFETJODPNIFSEJOHDBUT