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

ある日「Webエンジニアなら、Webサーバーは作れますよね」と言われたら? ~ 3つのJVM言語で作って学ぶ

ある日「Webエンジニアなら、Webサーバーは作れますよね」と言われたら? ~ 3つのJVM言語で作って学ぶ

技育祭 2021の発表資料です。

9aba2147bb6e43333fcc42e2afc570f2?s=128

Shunsuke Tadokoro

March 13, 2021
Tweet

Transcript

  1. ͋Δ೔
 
 ͱݴΘΕͨΒʁ ʙͭͷ+7.ݴޠͰ࡞ֶͬͯͿʙ ٕҭࡇ !UPEPLS 8FCΤϯδχΞͳΒ
 8FCαʔόʔ͸࡞Ε·͢ΑͶ

  2. ୭ͩ ాॴॣ༎!UPEPLS w גࣜձࣾϏζϦʔν)3.04ࣄۀ෦։ൃνʔϜϚωʔδϟʔ w 044ίϯτϦϏϡʔλʔ 1MBZ'SBNFXPSL 4DBMJLF+%#$ FUD 

    w ೥݄ϏζϦʔνʢ7JTJPOBMάϧʔϓʣ৽ଔೖࣾ w 4DBMB.BUTVSJεϐʔΧʔ w Ұࣇͷ෕👶 IUUQTXXXBNB[PODPKQEQ#':92/ SFGDN@TX@S@UX@EQ@$35:4(+57#1$15 IUUQTHJIZPKQNBHB[JOF4%BSDIJWF  IUUQTHJIZPKQNBHB[JOF4%BSDIJWF 
  3. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠

  4. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ాॴ͘Μ͸8FCΤϯδχΞͩΑͶʁ

  5. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ాॴ͘Μ͸8FCΤϯδχΞͩΑͶʁ ϋΠʂ

  6. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ాॴ͘Μ͸8FCΤϯδχΞͩΑͶʁ 8FCΤϯδχΞͬͯ͞ɺ8FCΤϯδχΞ͡ΌΜʁ ϋΠʂ

  7. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ాॴ͘Μ͸8FCΤϯδχΞͩΑͶʁ 8FCΤϯδχΞͬͯ͞ɺ8FCΤϯδχΞ͡ΌΜʁ 8FCαʔόʔ࡞Βͳ͍ͱʂʂʂ ϋΠʂ

  8. ഑ଐ͞Εͯ਺ϲ݄͕ܦͬͨ͋Δ೔ͷ͜ͱ ͋Δ೔ɺَڧ͍ઌഐΤϯδχΞ͕χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ాॴ͘Μ͸8FCΤϯδχΞͩΑͶʁ 8FCΤϯδχΞͬͯ͞ɺ8FCΤϯδχΞ͡ΌΜʁ 8FCαʔόʔ࡞Βͳ͍ͱʂʂʂ ϋΠʂ ΞοɺϋΠ

  9. ͓࿩͢͠Δ͜ͱ w 8FCαʔόʔͬͯԿͯ͠Δͷʁ w 4DBMB $MPKVSFʹ͍ͭͯ w 8FCαʔόʔΛ࡞Γͳ͕Βͭͷ+7.ݴޠΛֶ΅͏ w ͬ͘͟ΓΞʔΩςΫνϟ

    w ֤ݴޠͰ࣮૷ͯ͠ΈΔ w 4PDLFUͷѻ͍ w ਖ਼نදݱ w จࣈྻͷѻ͍ w Ϧιʔεͷ؅ཧ w ฒྻॲཧ w 8FCαʔόʔΛ࡞ͬͯɺԿΛಘͨʁ
  10. ͜͏ͯ͠
 8FCαʔόʔΛ࡞Δ೔ʑ͕
 ࢝·ͬͨ

  11. ͱ͸͍͑

  12. 8FCαʔόʔͬͯԿͯ͠Δͷʁ

  13. 8FCαʔόʔ͕΍͍ͬͯΔ͜ͱ w ΫϥΠΞϯτ͔Βͷ઀ଓΛ଴ͪड͚Δ w ΫϥΠΞϯτ͔ΒૹΒΕ͖ͯͨ)551ϦΫΤετΛύʔε͢Δ w ϦΫΤετʹج͍ͮͯ)551ϨεϙϯεΛੜ੒͢Δ w ΫϥΠΞϯτʹϨεϙϯεΛฦ͢

  14. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠

  15. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ ʢʮ)551Θ͔Γ΍͘͢ʯͰݕࡧͱʣ

  16. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ 8FCΤϯδχΞͳΒҰ࣍৘ใʹ౰ͨΒͳ͍ͱʂ ʢʮ)551Θ͔Γ΍͘͢ʯͰݕࡧͱʣ

  17. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ 8FCΤϯδχΞͳΒҰ࣍৘ใʹ౰ͨΒͳ͍ͱʂ 3'$Λಡ΋͏ͥʂʂʂ ʢʮ)551Θ͔Γ΍͘͢ʯͰݕࡧͱʣ

  18. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ 8FCΤϯδχΞͳΒҰ࣍৘ใʹ౰ͨΒͳ͍ͱʂ 3'$Λಡ΋͏ͥʂʂʂ ʢʮ)551Θ͔Γ΍͘͢ʯͰݕࡧͱʣ ΞοɺϋΠ

  19. )551ͷن֨Λཧղ͠Α͏ ௐ΂෺Λ͍ͯ͠Δͱɺ·ͨͯ͠΋َڧ͍ઌഐΤϯδχΞ͕
 χίχί͠ͳ͕Β࿩͔͚͖ͯͨ͠ 8FCΤϯδχΞͳΒҰ࣍৘ใʹ౰ͨΒͳ͍ͱʂ 3'$Λಡ΋͏ͥʂʂʂ ʢʮ)551Θ͔Γ΍͘͢ʯͰݕࡧͱʣ ΞοɺϋΠ ʢ3'$JTԿʣ

  20. 3'$ʢ3FRVFTU'PS$PNNFOUTʣ w *&5'ʹΑΔٕज़࢓༷ͷอଘɺެ։ܗࣜ w ϓϩτίϧ΍ϑΝΠϧϑΥʔϚοτͳͲ͕த৺ w )551͸3'$d

  21. IUUQTUPPMTJFUGPSHIUNMSGD

  22. IUUQIUUQXHPSH

  23. ؆қͳ࣮૷ͳΒ਺ඦߦఔ౓👍

  24. 1ZUIPOͷ4JNQMF)5514FSWFS w 1ZUIPOͷ4JNQMF)5514FSWFSͷڍಈΛࢀߟʹ͢Δͷ΋ྑ͍ w ܥ w ܥ $ python -m

    SimpleHTTPServer $ python -m http.server
  25. w 4DBMB w +BWB w 1ZUIPO w $MPKVSF w $PNNPO-JTQ

    w &MJYJS w %BSU
  26. w 4DBMB w +BWB w 1ZUIPO w $MPKVSF w $PNNPO-JTQ

    w &MJYJS w %BSU
  27. 8FCαʔόʔΛ࡞Γͳ͕Β ͭͷ+7.ݴޠΛֶ΅͏ʂ

  28. 4DBMB$MPKVSF

  29. 4DBMB

  30. 4DBMB w +BWBͱͷ૬ޓӡ༻ੑ w γʔϜϨεͳݺͼग़͠ɺ+BWBඪ४ϥΠϒϥϦͷ࠶ར༻ w ؆ܿੑ w লུՄೳͳߏจɺܕਪ࿦ɺڧྗͳඪ४ϥΠϒϥϦ w

    ந৅౓ͷߴ͍ίʔυɺ৽੍͍͠ޚߏจΛఆٛͰ͖Δදݱྗ w 8IBUͷڧௐɺ)PXͷӅณ w ੩తܕ෇͚ w ݕূՄೳੑɺϦϑΝΫλͷ͠΍͢͞ɺυΩϡϝϯτੑ
  31. IUUQTXXXMJIBPZJDPNQPTU'SPN'JSTU1SJODJQMFT8IZ4DBMBIUNM

  32. "$PNQJMFE-BOHVBHFUIBUGFFMT%ZOBNJD requests.post( "https://api.github.com/repos/lihaoyi/test/issues", data = ujson.Obj("title" -> "hello"), headers =

    Map("Authorization" -> s"token $token") )
  33. 4DBMBܕͷදݱྗ // `@`͔Β࢝·ͬͯ3จࣈҎ্16จࣈҎ಺ɺ@admin΍@Admin͸ڐ༰͠ͳ͍ type UserIdRule = StartsWith["@"] And MinSize[3] And

    MaxSize[16] And Not[MatchesRegex["(?i)@admin"]] val userId1: String Refined UserIdRule = "@todokr" // ҎԼ͸ίϯύΠϧΤϥʔ val userId2: String Refined UserIdRule = "@admin" val userId3: String Refined UserIdRule = "todokr" val userId4: String Refined UserIdRule = "@uryyyyyyyyyyyyyy"
  34. IUUQTFOHJOFFSJOHWJTJPOBMJODCMPHTDBMBSFpOFEOFXUZQF

  35. $MPKVSF

  36. $MPKVSF w -JTQ w จ๏͕গͳ͍ɺσʔλͱͯ͠ͷίʔυ w ؔ਺ܕϓϩάϥϛϯάͷͨΊͷݴޠ w ୈҰڃؔ਺ɺΠϛϡʔλϒϧͳσʔλߏ଄ɺ࠶ؼతͳϧʔϓ w

    +BWBͱͷ૬ޓӡ༻ੑ w ฒߦॲཧͷͨΊʹઃܭ w 3&1-Λ׆͔ͨ͠ΠϯλϥΫςΟϒΠϯΫϦϝϯλϧͳ։ൃ
  37. ϙʔϧɾάϨΞϜ 7JBXFC૑ۀऀ :$PNCJOBUPS૑ઃऀ IUUQTVQMPBEXJLJNFEJBPSHXJLJQFEJB DPNNPOTFF1BVMHSBIBN@YKQH

  38. -JTQͰྑ͍ϓϩάϥϜ͕ॻ͚ΔͳΒɺ࢖͏΂͖ͳΜͩɻ ͦ͏Ͱͳ͍ͳΒ͍͍ͬͨԿͷ໾ʹཱͭ ϙʔϧɾάϨΞϜ 7JBXFC૑ۀऀ :$PNCJOBUPS૑ઃऀ IUUQTVQMPBEXJLJNFEJBPSHXJLJQFEJB DPNNPOTFF1BVMHSBIBN@YKQH

  39. ී௨ͷౕΒͷ্Λߦ͚ɻ -JTQͰྑ͍ϓϩάϥϜ͕ॻ͚ΔͳΒɺ࢖͏΂͖ͳΜͩɻ ͦ͏Ͱͳ͍ͳΒ͍͍ͬͨԿͷ໾ʹཱͭ ϙʔϧɾάϨΞϜ 7JBXFC૑ۀऀ :$PNCJOBUPS૑ઃऀ IUUQTVQMPBEXJLJNFEJBPSHXJLJQFEJB DPNNPOTFF1BVMHSBIBN@YKQH

  40. ී௨ͷౕΒͷ্Λߦ͚ɻ -JTQͰྑ͍ϓϩάϥϜ͕ॻ͚ΔͳΒɺ࢖͏΂͖ͳΜͩɻ ͦ͏Ͱͳ͍ͳΒ͍͍ͬͨԿͷ໾ʹཱͭ :BIPPʹച٫ ϙʔϧɾάϨΞϜ 7JBXFC૑ۀऀ :$PNCJOBUPS૑ઃऀ IUUQTVQMPBEXJLJNFEJBPSHXJLJQFEJB DPNNPOTFF1BVMHSBIBN@YKQH

  41. ී௨ͷౕΒͷ্Λߦ͚ɻ -JTQͰྑ͍ϓϩάϥϜ͕ॻ͚ΔͳΒɺ࢖͏΂͖ͳΜͩɻ ͦ͏Ͱͳ͍ͳΒ͍͍ͬͨԿͷ໾ʹཱͭ Θͨ͠ ී௨ͷϓϩάϥϚ -JTQͰ΢ΣϒαʔϏεΛͭ͘Δͱ :BIPPʹԯԁͰങͬͯ΋Β͑Δʂʂʂ :BIPPʹച٫ ϙʔϧɾάϨΞϜ 7JBXFC૑ۀऀ

    :$PNCJOBUPS૑ઃऀ IUUQTVQMPBEXJLJNFEJBPSHXJLJQFEJB DPNNPOTFF1BVMHSBIBN@YKQH
  42. ίϯηϓτ͕໘ന͍ w ঢ়ଶʹ͍ͭͯͷߟ͑ํɺ*EFOUJUZ 4UBUF 7BMVFͷ෼཭ w γϯϓϧ͞ʹ͍ͭͯ ͍Ζ͍Ζܹࢗత

  43. IUUQCPYPGQBQFSTIBUFOBCMPHDPNFOUSZTJNQMF@NBEF@FBTZ

  44. -JTQͷγϯλοΫε ׅހͷ࢝·Γ͔ΒऴΘΓ·Ͱ͕୯Ґ (ԿΒ͔ͷॲཧ ॲཧͷର৅ͳͲ…)

  45. $MPKVSF͸Χοίͷछྨ͕ଟ͘ɺಡΈ΍͍͢ ͨͱ͑͹ؔ਺ͷҾ਺ $PNNPO-JTQ 4DIFNF $MPKVSF (defun square (x) (* x

    x)) (define (square x) (* x x)) (defn square [x] (* x x))
  46. 😌 େৎ෉

  47. 😌 ৴͍ͯͩ͘͡͞

  48. جຊจ๏Ͱ΢ΥʔϛϯάΞοϓ

  49. ࢛ଇԋࢉ

  50. ࢛ଇԋࢉ 12 + 40 10 - 1 2 * 3

    5 / 2 +BWB 4DBMB
  51. ࢛ଇԋࢉ 12 + 40 10 - 1 2 * 3

    5 / 2 +BWB 4DBMB (+ 12 40) (- 10 1) (* 2 3) (/ 5 2) ; -> 5/2 ෼਺Λѻ͏Ratioܕ $MPKVSF
  52. ม਺એݴ

  53. ม਺એݴ int x = 10; +BWB

  54. ม਺એݴ int x = 10; +BWB val x = 10

    val x: Int = 10 4DBMB
  55. ม਺એݴ int x = 10; +BWB val x = 10

    val x: Int = 10 4DBMB (def x 10) (let [y 10] (+ y 3)) ; y͸letͷׅހ಺͚ͩͰࢀরͰ͖Δ $MPKVSF
  56. ϝιουɾؔ਺એݴ

  57. ϝιουɾؔ਺એݴ public int f(int x) { return x + 1;

    } +BWB
  58. ϝιουɾؔ਺એݴ public int f(int x) { return x + 1;

    } +BWB def f(x: Int) = x + 1 4DBMB
  59. ϝιουɾؔ਺એݴ public int f(int x) { return x + 1;

    } +BWB (defn f [x] (+ x 1)) $MPKVSF def f(x: Int) = x + 1 4DBMB
  60. 👍

  61. ࠓճ༻ҙ࣮ͨ͠૷ w ىಈ͠ɺMPDBMIPTUͷಛఆͷϙʔτͰ)551ϦΫΤετΛ଴ͪड͚Δ w ରԠ͢Δ)551ϦΫΤετϝιου͸(&5ͷΈ
 ͦΕҎ֎ͷϝιου΋(&5ͱΈͳ͢ w QVCMJDσΟϨΫτϦΑΓ্ͷ֊૚΁ͷϦΫΤετʹ͸
 'PSCJEEFOΛฦ͢ w

    Ϧιʔεͷ.*.&͸֎෦ϑΝΠϧͰઃఆͰ͖Δ w ϦΫΤετΛϒϩοΫ͠ͳ͍ʢϚϧνεϨουʣ w ,FFQ"MJWF͸͠ͳ͍ɻίωΫγϣϯ͸౎౓DMPTF͢Δ w )551$BDIF͸͠ͳ͍ɻ͸ฦ͞ͳ͍
  62. IUUQTHJUIVCDPNUPEPLSTJNQMFIUUQTFSWFS

  63. ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ᵓᴷᴷ.JNF%FUFDUPSKBWB ᵓᴷᴷ3FRVFTUKBWB ᵓᴷᴷ3FRVFTU)BOEMFSKBWB ᵓᴷᴷ3FRVFTU1BSTFSKBWB ᵓᴷᴷ3FTQPOTFKBWB ᵓᴷᴷ4JNQMF+BWB)UUQ4FSWFSKBWB ᵋᴷᴷ8PSLFS5ISFBEKBWB 8FCαʔόʔΞϓϦέʔγϣϯ 3FRVFTU

    *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN )551ϦΫΤετͷύʔε ϦΫΤετʹԠͨ͡
 Ϩεϙϯεͷੜ੒ )551Ϩεϙϯεͷฦ٫
  64. ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ᵓᴷᴷ.JNF%FUFDUPSKBWB ᵓᴷᴷ3FRVFTUKBWB ᵓᴷᴷ3FRVFTU)BOEMFSKBWB ᵓᴷᴷ3FRVFTU1BSTFSKBWB ᵓᴷᴷ3FTQPOTFKBWB ᵓᴷᴷ4JNQMF+BWB)UUQ4FSWFSKBWB ᵋᴷᴷ8PSLFS5ISFBEKBWB 8FCαʔόʔΞϓϦέʔγϣϯ 3FRVFTU

    *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN )551ϦΫΤετͷύʔε ϦΫΤετʹԠͨ͡
 Ϩεϙϯεͷੜ੒ )551Ϩεϙϯεͷฦ٫
  65. ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ᵓᴷᴷ.JNF%FUFDUPSKBWB ᵓᴷᴷ3FRVFTUKBWB ᵓᴷᴷ3FRVFTU)BOEMFSKBWB ᵓᴷᴷ3FRVFTU1BSTFSKBWB ᵓᴷᴷ3FTQPOTFKBWB ᵓᴷᴷ4JNQMF+BWB)UUQ4FSWFSKBWB ᵋᴷᴷ8PSLFS5ISFBEKBWB 8FCαʔόʔΞϓϦέʔγϣϯ 3FRVFTU

    *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN )551ϦΫΤετͷύʔε ϦΫΤετʹԠͨ͡
 Ϩεϙϯεͷੜ੒ )551Ϩεϙϯεͷฦ٫
  66. ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ᵓᴷᴷ.JNF%FUFDUPSKBWB ᵓᴷᴷ3FRVFTUKBWB ᵓᴷᴷ3FRVFTU)BOEMFSKBWB ᵓᴷᴷ3FRVFTU1BSTFSKBWB ᵓᴷᴷ3FTQPOTFKBWB ᵓᴷᴷ4JNQMF+BWB)UUQ4FSWFSKBWB ᵋᴷᴷ8PSLFS5ISFBEKBWB 8FCαʔόʔΞϓϦέʔγϣϯ 3FRVFTU

    *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN )551ϦΫΤετͷύʔε ϦΫΤετʹԠͨ͡
 Ϩεϙϯεͷੜ੒ )551Ϩεϙϯεͷฦ٫
  67. ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ᵓᴷᴷ.JNF%FUFDUPSKBWB ᵓᴷᴷ3FRVFTUKBWB ᵓᴷᴷ3FRVFTU)BOEMFSKBWB ᵓᴷᴷ3FRVFTU1BSTFSKBWB ᵓᴷᴷ3FTQPOTFKBWB ᵓᴷᴷ4JNQMF+BWB)UUQ4FSWFSKBWB ᵋᴷᴷ8PSLFS5ISFBEKBWB 8FCαʔόʔΞϓϦέʔγϣϯ 3FRVFTU

    *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN )551ϦΫΤετͷύʔε ϦΫΤετʹԠͨ͡
 Ϩεϙϯεͷੜ੒ )551Ϩεϙϯεͷฦ٫
  68. ֤ݴޠͰ΍ͬͯΈΔ w 4PDLFUͷѻ͍ w ਖ਼نදݱ w จࣈྻͷѻ͍ w Ϧιʔεͷ։์ w

    ฒߦॲཧ
  69. 4PDLFUͷѻ͍

  70. 4PDLFU

  71. 4PDLFU w ௨৴ʹ͓͚ΔΤϯυϙΠϯτΛදݱͨ͠σʔλϞσϧ ֤ΤϯυϙΠϯτΛࣝผ͢Δ̎ͭͷ஋ɺ
 ͢ͳΘͪ*1ΞυϨεͱϙʔτ൪߸͸ɺ
 ଟ͘ͷ৔߹ιέοτ TPDLFU ͱݺ͹ΕΔɻ ʮ6/*9ωοτϫʔΫϓϩάϥϛϯάʯIUUQTXXXTFTIPQDPNQSPEVDUEFUBJM

  72. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ

  73. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ

  74. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ

  75. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ ઀ଓཁٻ

  76. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ ઀ଓ

  77. 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ 😂 😂

  78. 4PDLFUͷѻ͍ // αʔόʔιέοτͷੜ੒ ServerSocket serverSocket = new ServerSocket(8080); while (true)

    { // ઀ଓΛ଴ͪड͚Δɻ઀ଓ͞ΕΔ·ͰϒϩοΫɻ Socket socket = serverSocket.accept(); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); ... } ιέοτͷੜ੒ͱ઀ଓͷ଴ͪड͚
  79. 4PDLFUͷѻ͍ // αʔόʔιέοτͷੜ੒ val serverSocket = new ServerSocket(8080) while (true)

    { // ઀ଓΛ଴ͪड͚Δɻ઀ଓ͞ΕΔ·ͰϒϩοΫ val socket = serverSocket.accept val in = s.getInputStream val out = s.getOutputStream ... } ιέοτͷੜ੒ͱ઀ଓͷ଴ͪड͚
  80. 4PDLFUͷѻ͍ (let [server-socket (new ServerSocket 8080)] (while true (let [socket

    (.accept server-socket) in (.getInputStream socket) out (.getOutputStream socket)] ...))) ιέοτͷੜ੒ͱ઀ଓͷ଴ͪड͚
  81. 4PDLFUͷѻ͍ʹֶ͍ͭͯΜͩ͜ͱ w 4FSWFS4PDLFUΦϒδΣΫτΛੜ੒͠ɺ
 ΫϥΠΞϯτ͔Βͷ઀ଓΛBDDFQUͰ଴ͪड͚Δ w 4PDLFUΦϒδΣΫτʢΫϥΠΞϯτιέοτʣ͔Β
 *O0VUQVU4USFBN͕औಘͰ͖Δ w *OQVU4USFBN͔Β)551ϦΫΤετΛ3FBE͠ɺ
 0VUQVU4USFBNʹ)551ϨεϙϯεΛ8SJUF͢Δ

  82. ਖ਼نදݱ

  83. ਖ਼نදݱ w 4PDLFUͷ*OQVU4USFBNΛҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠

  84. ਖ਼نදݱ w 4PDLFUͷ*OQVU4USFBNΛҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠

  85. ਖ਼نදݱ w 4PDLFUͷ*OQVU4USFBNΛҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠

  86. ໊લ෇͖άϧʔϓ

  87. ໊લ෇͖άϧʔϓ w ਖ਼نදݱͷάϧʔϓʹ໊લΛ෇͚Δ͜ͱ͕Ͱ͖Δ w άϧʔϓͷॱং͕มΘͬͨͱͯ͠΋औΓग़͢ॲཧ͸ͦͷ··Ͱྑ͍ import java.util.regex.*; String regex =

    "(?<year>\\d+)/(?<month>\\d+)/(?<day>\\d+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher("2017/11/18"); if (m.find()) { System.out.println(m.group("year")); // 2017 System.out.println(m.group("month")); // 11 System.out.println(m.group("day")); // 18 }
  88. public static Pattern requestLinePattern = Pattern.compile("(?<method>.*) (?<path>.*?) (?<version>.*?)"); public Request

    fromInputStream(InputStream in){ BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String requestLine = reader.readLine(); Matcher matcher = requestLinePattern.matcher(requestLine); if (!matcher.find()) return null; String method = matcher.group("method"); String targetPath = matcher.group("path"); String httpVersion = matcher.group("version"); return new Request(method, targetPath, httpVersion); } ໊લ෇͖άϧʔϓ ϦΫΤετϥΠϯͷ֤ཁૉʹ໊લΛ෇͚ͯநग़
  89. ύλʔϯϚον S

  90. ύλʔϯϚον w +BWBͷTXJUDIจʹࣅ͍ͯΔ͕ɺΑΓॊೈͰڧྗ w ஋ʹҰக͢Δ͔͚ͩͰͳ͘ɺܕ΍ߏ଄Ͱ෼ذͤ͞Δ͜ͱ͕Ͱ͖Δ 0 match { case 0

    => "Zero" // "Zero" case _ => "Other" } List(1, 2, 3) match { case List(_, x, _) => x // 2 case _ => -1 } 1 match { x: Int => s"$x͸Int" // 1͸Int x: String => s"$x͸String" x => s"$x͸???" }
  91. ύλʔϯϚον w ਖ਼نදݱΦϒδΣΫτʹରͯ͠΋Ϛονͤ͞Δ͜ͱ͕Ͱ͖Δ val pattern = "(.+)/(.+)/(.+)".r //.rͰregexܕ "2017/11/18" match

    { case pattern(y, m, d) => s"${y}೥${m}݄${d}೔" case _ => "???" }
  92. ύλʔϯϚον val pattern = "(.+) (.+) (.+)".r requestLine match {

    case pattern(method, path, version) => Some(Request(method, path, version)) case _ => None } 3FRVFTU1BSTFSTDBMBʢൈਮʣ
  93. 0QUJPOܕ requestLine match { case pattern(method, path, version) => Some(Request(method,

    path, version)) case _ => None } w +BWBͰ͍͏0QUJPOBM w 4PNFͱ/POF͔ΒͳΔܕʢ୅਺తσʔλܕʣ w ஋͕͋Δ͔ͳ͍͔෼͔Βͳ͍ঢ়ଶΛද͢ w ஋͕ଘࡏ͢Δ͔ͷνΣοΫΛڧ੍Ͱ͖Δ
  94.  SFpOE

  95. SFpOE w ਖ਼نදݱʹϚονͨ͠จࣈྻΛऔಘ w Ҿ਺ʹάϧʔϓԽͨ͠ਖ਼نදݱΦϒδΣΫτΛ౉͢ͱɺ
 ઌ಄ʹ͸Ϛονͨ͠จࣈྻશମɺҎ߱ʹΩϟϓνϟ͞ΕͨจࣈྻͷϕΫλʔ ;; #"" ͸java.util.regex.PatternͷϦςϥϧ (re-find

    #"(.+)/(.+)/(.+)" "2017/11/18") ;; => ["2017/11/18" "2017" "11" "18"] ;; restͰઌ಄Ҏ֎ͷཁૉΛऔಘ (rest (re-find #"(.+)/(.+)/(.+)" "2017/11/18")) ;; => ("2017" "11" "18")
  96. [JQNBQ w ڧྗͳίϨΫγϣϯϥΠϒϥϦ͸$MPKVSFͷಛ௃ w [JQNBQ͸ͭͷίϨΫγϣϯ͔Β.BQΛ࡞Δ w $MPKVSFͰ͸ΫϥεΑΓ΋.BQΛ޷Ή (zipmap [:a :b

    :c] [1 2 3]) ;; => {:a 1, :b 2, :c 3}
  97. SFpOE [JQNBQ (let [line "GET / HTTP/1.1"] (zipmap [:method :path

    :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} ϦΫΤετϥΠϯͷ֤ཁૉΛ.BQʹม׵
  98. SFpOE [JQNBQ <NFUIPEQBUIWFSTJPO> <(&5)551> (let [line "GET / HTTP/1.1"] (zipmap

    [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} ϦΫΤετϥΠϯͷ֤ཁૉΛ.BQʹม׵
  99. SFpOE [JQNBQ <NFUIPEQBUIWFSTJPO> <(&5)551> (let [line "GET / HTTP/1.1"] (zipmap

    [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} ϦΫΤετϥΠϯͷ֤ཁૉΛ.BQʹม׵
  100. SFpOE [JQNBQ <NFUIPEQBUIWFSTJPO> <(&5)551> (let [line "GET / HTTP/1.1"] (zipmap

    [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} ϦΫΤετϥΠϯͷ֤ཁૉΛ.BQʹม׵
  101. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ

  102. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ

  103. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ఴࣈͰΞΫηε͢ΔΑΓ҆৺

  104. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ύλʔϯϚον
 S ఴࣈͰΞΫηε͢ΔΑΓ҆৺

  105. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ύλʔϯϚον
 S ఴࣈͰΞΫηε͢ΔΑΓ҆৺ ߏ଄ͷ෼ղʹ΋࢖͑Δ

  106. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ύλʔϯϚον
 S SFpOE
  ఴࣈͰΞΫηε͢ΔΑΓ҆৺ ߏ଄ͷ෼ղʹ΋࢖͑Δ

  107. ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ύλʔϯϚον
 S SFpOE
  ఴࣈͰΞΫηε͢ΔΑΓ҆৺ ߏ଄ͷ෼ղʹ΋࢖͑Δ ݁Ռ͸ίϨΫγϣϯɺίϨΫγϣϯૢ࡞ͱ૊Έ߹Θͤͯ

  108. จࣈྻͷѻ͍

  109. จࣈྻ݁߹ w ϨεϙϯεʢΦϒδΣΫτϚοϓʣ͔Β
 )551ϨεϙϯεϔομΛ૊Έཱ͍ͯͨ public class Response { public final

    Status status; public final String contentType; public final int contentLength; public final byte[] body; }
  110.  4USJOH#VJMEFS

  111. 4USJOH#VJMEFS String response = "HTTP/1.1 " + status.statusCode + CRLF

    + "Server: SimpleJavaHttpServer" + CRLF + "Content-Type: " + contentType + CRLF + "Content-Length: " + 
 String.valueOf(contentLength) + CRLF + "Connection: Close" + CRLF + CRLF; 3FTQPOTFΦϒδΣΫτΛ)551Ϩεϙϯε΁ม׵
  112. 4USJOH*OUFSQPMBUJPO 5SJQMF2VPUF

  113. 4USJOH*OUFSQPMBUJPO w จࣈྻϦςϥϧͷલʹTΛ෇͚Δͱɺม਺Λల։Ͱ͖Δ val price = 1000 s"Price is $price"

    // => Price is 1000
  114. 5SJQMF2VPUF "Hello triple quote!\nHello stripMargin!" """Hello triple quote! Hello stripMargin!"""

    """|Hello triple quote! |Hello stripMargin!""".stripMargin w վߦΛؚΉจࣈྻΛຒΊࠐΉʹ͸ɺΛ࢖͏ w ΠϯσϯτΛଗ͑Δʹ͸Πϯσϯτจࣈ c ͱTUSJQ.BSHJOΛ࢖͏
  115. 4USJOH*OUFSQPMBUJPOͱ5SJQMF2VPUF val response = s"""HTTP/1.1 ${status.value} |Date: ${rfc1123Formatter.format(now)} |Server: SimpleScalaHttpServer

    |Content-Type: $contentType |Content-Length: ${body.length.toString} |Connection: Close | |""".stripMargin 3FTQPOTFΦϒδΣΫτΛ)551Ϩεϙϯε΁ม׵
  116. TUS

  117. w $MPKVSFͰ͸จࣈྻͷ݁߹͸ Ͱ͸ͳ͘TUS w Մม௕Ҿ਺ɺ4ࣜͳΒͰ͸ TUS (+ "hoge" "fuga") ClassCastException

    java.lang.String cannot be cast to java.lang.Number clojure.lang.Numbers.add (Numbers.java:128) (str "hoge" "fuga" "piyo") // => hogefugapiyo
  118. TUS (let [header (str "HTTP/1.1" SP status SP reason-phrase CRLF

    "Content-Length:" (count body) CRLF "Content-Type:" content-type CRLF "Connection: Close" CRLF CRLF)] ...) 3FTQPOTFΦϒδΣΫτΛ)551Ϩεϙϯε΁ม׵
  119. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ

  120. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS

  121. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS ࠷దԽʹࣗ৴͕ͳ͚Ε͹KBWBQD

  122. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS 4USJOH*OUFSQPMBUJPO
 5SJQMF2VPUF ࠷దԽʹࣗ৴͕ͳ͚Ε͹KBWBQD

  123. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS 4USJOH*OUFSQPMBUJPO
 5SJQMF2VPUF ࠷దԽʹࣗ৴͕ͳ͚Ε͹KBWBQD ͪΐͬͱͨ͠ςϯϓϨʔτΤϯδϯΈ͍ͨʹ࢖͑Δ

  124. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS 4USJOH*OUFSQPMBUJPO
 5SJQMF2VPUF TUS ࠷దԽʹࣗ৴͕ͳ͚Ε͹KBWBQD ͪΐͬͱͨ͠ςϯϓϨʔτΤϯδϯΈ͍ͨʹ࢖͑Δ

  125. จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS 4USJOH*OUFSQPMBUJPO
 5SJQMF2VPUF TUS ࠷దԽʹࣗ৴͕ͳ͚Ε͹KBWBQD ͪΐͬͱͨ͠ςϯϓϨʔτΤϯδϯΈ͍ͨʹ࢖͑Δ 4ࣜͳΒͰ͸

  126. Ϧιʔεͷ؅ཧ

  127. Ϧιʔεͷ؅ཧ w ετϦʔϜ΍%#ίωΫγϣϯɺιέοτ͸࢖͍ऴΘͬͨΒDMPTF w ๨ΕΔͱϝϞϦϦʔΫͷݪҼʹͳΔ͜ͱ͕͋Δ w खͰDMPTFॻ͖ͨ͘ͳ͍ʂ😫

  128. 5SZXJUI3FTPVSDFT

  129. 5SZXJUI3FTPVSDFT try (InputStream in = new FileInputStream(file)) { // Կ͔ϦιʔεΛѻ͏ॲཧ

    } // try۟Λൈ͚ͨΒclose w USZ۟Λൈ͚ͨΒࣗಈͰDMPTF w ର৅͸KBWBJP$MPTFBCMF KBWBMBOH"VUP$MPTFBCMFͷ࣮૷Ϋϥε
  130. -PBO1BUUFSO

  131. -PBO1BUUFSO w ʮआΓͨΒฦ͢ʯΛ࣮֬ʹߦ͏ͨΊͷΠσΟΦϜ w ͔͋ͨ΋ݴޠ੍͕࣋ͭޚߏ଄ͷΑ͏ͳϝιουΛɺ
 ϓϩάϥϚ͕؆୯ʹఆٛͰ͖Δͷ΋4DBMBͷΑ͍ͱ͜Ζ val reader = new

    BufferedReader(...) using(reader) { r => // readerΛ࢖ͬͨԿ͔ͷॲཧ } // ϒϩοΫΛൈ͚ͨΒreader͸close͞Ε͍ͯΔ ˞4DBMB͔Βඪ४ϥΠϒϥϦʹˢͱ΄΅ಉ౳ͷTDBMBVUJM6TJOH͕௥Ճ͞Ε·͕ͨ͠ɺ
 ΠϝʔδΛ௫ΉͨΊʹࣗ෼Ͱ࣮૷ͯ͠Έ·͢
  132. -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A):

    A = { try { f(resource) } finally { resource.close() } }
  133. -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A):

    A = { try { f(resource) } finally { resource.close() } } ܕม਺3͸$MPTFBCMFɻDMPTFͱ͍͏ϝιουΛ࣋ͭ΋ͷɻ
  134. -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A):

    A = { try { f(resource) } finally { resource.close() } } 3ܕͷԿ͔Λड͚औΓɺԿΒ͔ͷܕ"Λฦؔ͢਺ΛҾ਺ʹͱΔ
  135. -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A):

    A = { try { f(resource) } finally { resource.close() } } Ϧιʔεʹରͯؔ͠਺Λద༻
  136. -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A):

    A = { try { f(resource) } finally { resource.close() } } ࠷ޙʹDMPTF
  137. -PBO1BUUFSO using(socket) { s => val in = s.getInputStream val

    out = s.getOutputStream val request = parser.fromInputStream(in) val response = request.map(handleRequest) response.foreach(_.writeTo(out)) } VTJOHϒϩοΫΛൈ͚ͨΒɺTPDLFUΛDMPTF͢Δ
  138. XJUIPQFO

  139. w -PBO1BUUFSOʹࣅͨXJUIPQFOͱ͍͏ϚΫϩ w MFUͱಉ͡Α͏ͳײ͡Ͱ࢖͏ XJUIPQFO (with-open [f (io/file "test.txt")] ...)

  140. XJUIPQFO (with-open [s socket] (-> (request-parser/from-input-stream (.getInputStream s)) (request-handler/handle-request) (response-writer/write

    (.getOutputStream s)))) XJUIPQFOΛൈ͚ͨΒɺTPDLFUΛDMPTF͢Δ
  141. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ

  142. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT

  143. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT USZ۟Λൈ͚Δ࣌ʹDMPTF

  144. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT -PBO1BUUFSO USZ۟Λൈ͚Δ࣌ʹDMPTF

  145. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT -PBO1BUUFSO USZ۟Λൈ͚Δ࣌ʹDMPTF ؔ਺͕஋Ͱ͋Δ͜ͱΛ׆͔͠ɺ੍ޚߏจͷΑ͏ʹݟͤΔ

  146. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT -PBO1BUUFSO XJUIPQFO USZ۟Λൈ͚Δ࣌ʹDMPTF ؔ਺͕஋Ͱ͋Δ͜ͱΛ׆͔͠ɺ੍ޚߏจͷΑ͏ʹݟͤΔ

  147. Ϧιʔεͷ؅ཧʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT -PBO1BUUFSO XJUIPQFO USZ۟Λൈ͚Δ࣌ʹDMPTF ؔ਺͕஋Ͱ͋Δ͜ͱΛ׆͔͠ɺ੍ޚߏจͷΑ͏ʹݟͤΔ DMPTFͯ͘͠ΕΔMFUΈ͍ͨͳΠϝʔδ

  148. ฒߦॲཧ

  149. ฒߦॲཧ w ϦΫΤετΛγϦΞϧʹॲཧ͢ΔͱଞͷϦΫΤετΛ଴ͨͤͯ͠·͏ w ͳͷͰϦΫΤετΛड͚෇͚ͨઌ͸ฒߦʹॲཧ͢Δ w +7.ݴޠͳͷͰϚϧνεϨουͰ

  150. 5ISFBE &YFDVUPS4FSWJDF

  151. 5ISFBE class HogeThread extends Thread { public void run() {

    // Կ͔ඇಉظʹ࣮ߦ͍ͨ͠ॲཧ } } HogeThread h = new HogeThread(); h.start(); class FugaRunnable implements Runnable { public void run() { // Կ͔ඇಉظʹ࣮ߦ͍ͨ͠ॲཧ } } FugaRunnable f = new Thread(new FugaRunnable()); f.start(); 5ISFBEΛFYUFOET3VOOBCMFΛJNQMFNFOUT
  152. 5ISFBE public class WorkerThread extends Thread { private Socket socket;

    private RequestParser parser; private RequestHandler handler; public WorkerThread( Socket socket, RequestParser parser, RequestHandler handler) { ... 5ISFBEͷఆٛ 5ISFBEͷىಈ Thread worker = new WorkerThread(socket, parser, handler); worker.start();
  153. &YFDVUPS4FSWJDF ExecutorService cachedPool = Executors.newCachedThreadPool(); cachedPool.execute(runnable); ExecutorService fixedPool = Executors.newFixedThreadPool(4);

    fixedPool.execute(runnable); w ΑΓߴਫ४ͳฒྻॲཧͷͨΊͷ࢓૊Έ w εϨουϓʔϧͷछྨ΋ࢦఆͰ͖Δ
  154. 'VUVSF

  155. 'VUVSF w 'VUVSFBQQMZ͸౉͞ΕͨॲཧΛඇಉظʹ࣮ߦ w ͍ͭͲͷΑ͏ʹඇಉظʹ࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈ import scala.concurrent.Future // ForkJoinPoolɺσϑΥϧτͰ͸ίΞ਺෼ͷฒྻ౓Ͱॲཧ
 import

    scala.concurrent.ExecutionContext.Implicits.global val result: Future[User] = Future { // .apply͸লུͰ͖Δ userRepository.fetch(userId) } result.map(user => user.id) result.flatMap(user => tweetRepository.fetch(user.id))
  156. &YFDVUJPO$POUFYU͸Ͳ͏ड͚औΔʁ w 'VUVSFBQQMZʹ͸Ҿ਺ϒϩοΫ͕ͭ w ͭ໨ͷҾ਺ϒϩοΫͰ&YFDVUJPO$POUFYUΛड͚औΔ object Future { ... def

    apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = unit.map(_ => body) ... } Future { userRepository.fetch(user) } Future.apply( userRepository.fetch(user) )
  157. JNQMJDJU8IBUͱ)PXͷ෼཭ w )PX͕ڊେʹͳΔͱɺίʔυͷຊདྷͷҙਤ͕ຒ΋Εͯ͠·͏ w JNQMJDJUͷେ͖ͳϞνϕʔγϣϯ͸)PXͷӅณ w 8IBUͱ)PXΛ෼཭͢Δ͜ͱͰɺ໨తΛ୺తʹࣔ͢͜ͱ͕Ͱ͖Δ val values: Seq[(String,

    Option[Int])] val sorted = sort(values)( tuple2Comparator( stringComparator, optionComparator(intComparator))) val sorted = sort(values) // implicit
  158. IUUQHBLV[[[[HJUIVCJPTMJEFTJNQMJDJU@SFJOUSPEVDUJPO

  159. UISFBE

  160. $MPKVSFͷฒߦॲཧؔ਺ w $MPKVSFͷฒߦॲཧؔ਺͸ͨ͘͞Μ͋Δ w HP w UISFBE w TFOE w

    TFOEPGG w GVUVSF w FUD
  161. $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM  ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠

    GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺   UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ
  162. *0ό΢ϯυ$16ό΢ϯυ ΞϓϦέʔγϣϯͷʮෛՙʯ͸ɺ
 *0ό΢ϯυͱ$16ό΢ϯυͷछྨʹେผ͞ΕΔ w *0ό΢ϯυ w *0͕ύϑΥʔϚϯεͷϘτϧωοΫ w $16͸ʮ଴ͪʯ͕ଟ͘ͳΔ w

    σΟεΫΞΫηε΍ϦϞʔτ௨৴ͳͲ w$16ό΢ϯυ w $16͕ύϑΥʔϚϯεͷϘτϧωοΫ w $16͸ϑϧՔಇ w େن໛ͳՊֶܭࢉͳͲ
  163. $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM  ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠

    GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺   UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ
  164. $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM  ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠

    GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺   UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ
  165. UISFBE (thread (with-open [s socket in (.getInputStream s) out (.getOutputStream

    s)] (-> (request-parser/from-input-stream in) (request-handler/handle-request) (response-writer/write out)))) $BDIFE5ISFBE1PPMΛ࢖ͬͨฒྻॲཧ
  166. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ

  167. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF

  168. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF

  169. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF 'VUVSF FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF

  170. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF 'VUVSF FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF 5ISFBE্ཱͪ͛Ͱ͸ͳ͍ɻ
 Ͳ͏࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈɻ

  171. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF 'VUVSF UISFBE FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF 5ISFBE্ཱͪ͛Ͱ͸ͳ͍ɻ
 Ͳ͏࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈɻ

  172. ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF 'VUVSF UISFBE FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF 5ISFBE্ཱͪ͛Ͱ͸ͳ͍ɻ
 Ͳ͏࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈɻ *0$16ό΢ϯυ͔Λҙࣝ͠Α͏

  173. 8FCαʔόʔΛ࡞ͬͯ ԿΛಘͨʁ

  174. ͪΐͬͱਂ͘જΔ༐ؾ

  175. ϓϩάϥϛϯάݴޠ΍8FCϑϨʔϜϫʔΫ͸
 ͜Ε·ͰͲͷΑ͏ʹมԽ͖͔ͯͨ͠ʁ

  176. ʮ3FBEBCMF4DBMBʯJO4DBMB.BUTVSJ
 !HBLV[[[[ ϓϩάϥϛϯάݴޠͷਐԽͷྺ࢙͸ɺ ͍͔ʹ)PXΛӅ΃͍ͯ͠
 8IBUΛ୺తʹදݱͰ͖ΔΑ͏ʹ͢Δ͔ɺͷ
 ྺ࢙Ͱ΋͋Γ·͢

  177. ྫ͑͹+BWBͷ4USFBN"1*

  178. ྫ͑͹+BWBͷ4USFBN"1* ʮϦετΛॱ൪ʹ͞Β͍ɺ
 ɹۮ਺ͩͬͨΒϦετʹ٧ΊΔʯ ɹͱ͍͏खଓ͖ʢ)PXʣ

  179. ྫ͑͹+BWBͷ4USFBN"1* खଓ͖ΛӅṭ͠ɺ
 ʮۮ਺ͷΈͷϦετΛ࡞Δʯ ɹͱ͍͏໨తʢ8IBUʣʹϑΥʔΧε

  180. ϑϨʔϜϫʔΫ΍ϥΠϒϥϦͰ΋ w ྫ %#͔ΒϨίʔυΛ݅औಘ w ʮ%#ʹͲ͏͍͏42-Λൃߦ͢Δ͔ʯͱ͍͏)PXΛӅณ͠ɺ
 ʮ+PCΛ*%ͰϑΟϧλϦϯάͯ݅͠औಘ͢Δʯͱ͍͏8IBUΛදݱ

  181. ͦͷҰํͰ͜Μͳ͜ͱ΋ w ؆୯ͦ͏ʹʮݟ͑ΔʯϑϧελοΫ8FCϑϨʔϜϫʔΫ w ͪΐͬͱ΍΍͍͜͜͠ͱΛ΍Ζ͏ͱ͢Δͱɺ্͙͢ख͍͔͘ͳ͘ͳΔ w ʮ)551ϨεϙϯεϔομΛݟΖʯ w ʮ$POUFOU5ZQF͕PDUFUTUSFBN͔ͩΒʜʯ w

    ʮNVMUJQBSUGPSNEBUB͕ʜʯ w ʮ+PJOͨͭ͠΋Γ͕αϒΫΤϦʹͳͬͯΔͷͰ͸ʁʯ w ʮ42-ͷ࣮ߦܭը͕ʜʯ
  182. ʮΫϥʔΫͷୈࡾ๏ଇʯΞʔαʔɾ$ɾΫϥʔΫ ߴ౓ʹൃୡٕͨ͠ज़͸ɺ
 ຐ๏ͱݟ෼͚͕͔ͭͳ͍

  183. ͳͥʮϋϚΔʯͷ͔ʁ w υΩϡϝϯτͷαϯϓϧίʔυWTʮ࣮ઓʯͷίʔυ w ྆ऀͷဃ཭͸ந৅ԽͷϨΠϠʔΛॏͶΔ΄Ͳେ͖͘ͳΔ w ݁ہ͸ԼͷϨΠϠʔͷ஌ࣝΛ஌͍ͬͯΔඞཁ͕͋Δ

  184. ʮ࿙Εͷ͋Δந৅Խͷ๏ଇʯ w CZ+PFM4QPMTLZ w ந৅Խͱ͸ɺҰ౓ʹ஫໨͢΂͖֓೦ΛݮΒ͢͜ͱ΍ɺ
 ͦͷ࢓૊Έͷ͜ͱ w ந৅Խ͸͢΂ͯɺఔ౓ͷࠩͦ͋͜Εɺ࿙Ε͕͋Δ

  185. 8FCϑϨʔϜϫʔΫͷʮந৅Խͷ࿙Εʯ w ϑϧελοΫͳ8FCϑϨʔϜϫʔΫ͸࿙Ε͕ݦஶ w ໘౗ͳ࡞ۀΛந৅Խ͠ɺ࡞ۀΛޮ཰Խͯ͘͠ΕΔ w ͔͠͠໘౗ͳ෦෼Λ׬શʹӅณͯ͘͠ΕΔΘ͚Ͱ͸ͳ͍ w ͋͘·Ͱ΋ʮޮ཰ԽʯͷͨΊͷந৅ԽͰ͋Γɺ
 ʮԿ͕ى͖͍ͯΔ͔ʯΛҙࣝ͢Δඞཁ͕͋Δ

    w )551ɺ42-ɺ$16ɺϝϞϦɺ*0ɺωοτϫʔΫɺFUD
  186. ࿙Εͷ͋Δந৅ԽͰى͖Δ͜ͱ w ϓϩάϥϛϯάݴޠ΍8FCϑϨʔϜϫʔΫ͸ɺந৅ԽʹΑͬͯɺ
 )PXͰ͸ͳ͘8IBUʹूதͰ͖ΔΑ͏ʹਐԽ͍ͯ͘͠ w 8IBUʹूதͰ͖Δར఺͸େ͖͍͕ɺ
 ͦͷந৅Խ͸ඞͣ͠΋׬શͰ͸ͳ͘ɺ
 ݁ہ͸ԼͷϨΠϠʔͷ)PXΛ஌Βͳ͍ͱઌʹਐΊͳ͍͜ͱ͕͋Δ

  187. ʮ+PFMPO4PGUXBSFʯ+PFM4QPMTLZ ࿙Εͷ͋Δந৅Խͷ๏ଇʹ͏·͘ରॲ͢Δ
 །Ұͷํ๏͸ɺͦͷந৅Խ͕ͲͷΑ͏ʹػೳ͠ɺ
 ͦΕ͕ԿΛந৅Խ͍ͯ͠Δͷ͔ΛֶͿ͜ͱͩɻ

  188. ಘͨ΋ͷͪΐͬͱਂ͘જΔ༐ؾ w ʮ࿙Εͷ͋Δந৅Խʯͷ΋ͱͰ͸ɺ໰୊ղܾͷͨΊʹ
 ීஈ৮Δٕज़ͷԼͷϨΠϠʔʹજΔ͜ͱ͕ආ͚ΒΕͳ͍
 ͔ͭɺ๛෋ͳ৘ใ͕͋Δͱ΋ݶΒͳ͍ w 8FCαʔόʔΛ࡞Δ͜ͱͰɺ8FCϑϨʔϜϫʔΫ͕ͲΜͳ࢓ࣄΛ ͍ͯ͠Δ͔΋ͳΜͱͳ͘෼͔ΔΑ͏ʹ w ӳޠͷҰ࣍৘ใʹ౰ͨΔ͕͍ͤͭͨ͘͜ͱͰɺ


    ະ຋༁ͷ৽͍ٕ͠ज़ͷυΩϡϝϯτͳͲ΋ԲͤͣಡΊΔΑ͏ʹ w ʮ࢓ࣄͰ࢖͍ͬͯΔϑϨʔϜϫʔΫ΍ϛυϧ΢ΣΞͷίʔυ΋
 ಡΜͰΈΑ͏ɻ͋ΘΑ͘͹ίϯτϦϏϡʔτͯ͠ΈΑ͏ʯͱ
 ͪΐͬͱਂ͘જͬͯΈΔ༐ؾˍڵຯΛ͖͔͚࣋ͭͬʹ
  189. 8FCαʔόʔΛ࡞ͬͯΈΔ͜ͱ͕ɺ
 Έͳ͞Μͷʮਂ͍ʯΤϯδχΞͷΩϟϦΞΛ
 ܗ࡞Δ͖͔͚ͬʹͳΕ͹͏Ε͍͠Ͱ͢

  190. 🙏 ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ

  191. ʢ࣌ؒʹ༨༟͕͋Ε͹ʣ ίʔυϦʔσΟϯάλΠϜʂ

  192. None
  193. None