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

プルプル…ボクはわるいScalaじゃないよ

 プルプル…ボクはわるいScalaじゃないよ

2017/12/21に開催された「教養としてのScala ~ そろそろ始めてみたい2017冬」で使用された発表資料です。

4e1f5a8e5bdb0fffe48d0224144faf1f?s=128

Tatsuya Iwamatsu

December 22, 2017
Tweet

Transcript

  1. ϓϧϓϧʜ ϘΫ͸ΘΔ͍εΧϥ͡Όͳ͍Α ೥݄೔ גࣜձࣾϏζϦʔν ؠদཽ໵

  2. ओ࠵ऀͷ൓Ԡ

  3. ࣗݾ঺հ ؠদཽ໵ גࣜձࣾϏζϦʔν)3.04ࣄۀ෦ ೥݄ೖࣾ ೖࣾҎདྷ4DBMBʹΑΔ"54˞։ൃʹܞΘΔ υϥΫΤ͸͔Βશ෦ϓϨΠࡁ ͕·ͩΫϦΞͰ͖͍ͯ·ͤΜ ༡ͼ͍ͨ ˞"QQMJDBOU5SBDLJOH4ZTUFN

  4. ಥવͰ͕͢4DBMBͷΠϝʔδ͸ʁ

  5. ؔ਺ܕ

  6. Ϟφυ

  7. มͳࣄݴ͏ͱౖΒΕΔ

  8. ͳΜ͔ා͍ʂ

  9. ͳΜ͔ා͍ʂ

  10. Ͱ΋ͪΐͬͱ·ͬͯʂ

  11. 4DBMB͸ා͘ͳ͍Αʂ ͳΜͱεΧϥ͕͓͖͕͋Γ ͳ͔·ʹͳΓͨͦ͏ʹͪ͜ΒΛΈ͍ͯΔ ͳ͔·ʹͯ͋͛͠·͔͢ʁ ͸͍ ͍͍͑

  12. ࠓ೔ͷझࢫ ଞͷݴޠ஌ࣝΛϕʔεʹ4DBMBΛֶͿ

  13. ࠓ೔ͷझࢫ ଞͷݴޠ஌ࣝΛϕʔεʹ4DBMBΛֶͿ ා͘ͳ͍ʂ

  14. ࠓ೔ͷझࢫ ଞͷݴޠ஌ࣝΛϕʔεʹ4DBMBΛֶͿ ා͘ͳ͍ʂ 4DBMBΛ஥ؒʹ͠Α͏ʂ

  15. 4DBMBͷجຊΛ஌Ζ͏ʂ Α͘Θ͔Βͳ͍

  16. 4DBMBͷجຊΛ஌Ζ͏ʂ Α͘Θ͔Βͳ͍ ͜Θ͍ʜ

  17. 4DBMBͷجຊΛ஌Ζ͏ʂ Α͘Θ͔Δ

  18. 4DBMBͷجຊΛ஌Ζ͏ʂ ͜Θ͘ͳ͍ʂ Α͘Θ͔Δ

  19. ࢛ଇԋࢉ 1 + 1 2 - 1 2 * 2

    4 / 2 3VCZ 1ZUIPO 4DBMB 1 + 1 2 - 1 2 * 2 4 / 2 1 + 1 2 - 1 2 * 2 4 / 2
  20. ׬શʹҰகʂ

  21. ม਺ɾ഑ྻ 3VCZ 1ZUIPO 4DBMB foo = [1, 2, 3] print(foo)

    foo = [1, 2, 3] print(foo) val foo = List(1, 2, 3) print(foo)
  22. ͍͍ͩͨҰகʂ

  23. ϝιου 3VCZ 1ZUIPO 4DBMB def foo print("hello") end foo() def

    foo(): print("hello") foo() def foo = { println("hello") } foo()
  24. GPSJG 3VCZ 1ZUIPO 4DBMB for x in 0..2 do puts(x)

    end for x in range(3): print(x) for (n <- 0 to 2) { println(n) } b = true if b then puts("true!") else puts("false!") end b = True if b: print("true!") else: print("false!") val b = true if (b) { println("true!") } else { println("false!") }
  25. TXJUDI 3VCZ 1ZUIPO 4DBMB x = "Ruby" case x when

    "Ruby" then puts("this is ruby") when "Python" then puts("this is python") when "Scala" then puts("this is scala") end o = "Python" if o is "Ruby": print("this is ruby!") elif o is "Python": print("this is python!") elif o is "Scala": print("this is scala!") val o = "Scala" o match { case "Ruby" => println("this is ruby!") case "Python" => println("this is python!") case "Scala" => println("this is scala!") case _ => // No Action }
  26. ͦΜͳʹมΘΒͳ͍Ͱ͢Ͷ☺

  27. Ϋϥε 3VCZ 1ZUIPO 4DBMB class Foo def say() puts("Foo!") end

    end Foo.new.say() class Foo: def say(self): print("Foo!") Foo().say() class Foo { def say() = println("Foo!") } new Foo().say()
  28. ΋͏4DBMB͕ॻ͚·͢Ͷʂ

  29. EXBOHP͞Μͷࢿྉ΋ࢀߟʹ IUUQEXBOHPHJUIVCJPTDBMB@UFYU

  30. ஥ؒʹͯ͠ΈΑ͏ʂ ͜Μͳͱ͖Ͳ͏ॻ͘ͷʁ Λ͓͑ͯ͞ΈΑ͏ʂ

  31. ίϨΫγϣϯૢ࡞ 3VCZ 1ZUIPO 4DBMB [1,2,3].map { |x| x + 1

    } map(lambda x: x + 1, [1,2,3]) [x + 1 for x in [1, 2, 3]] List(1,2,3).map { x => x + 1 } List(1,2,3).map(_ + 1) [1,2,3].select { |x| x % 2 == 0 } filter(lambda x: x % 2 == 0, [1,2,3]) [x for x in [1,2,3] if x % 2 == 0] List(1,2,3).filter(_ % 2 == 0)
  32. γϯϓϧʹॻ͚·͢Αʂ

  33. μοΫλΠϐϯά 3VCZ class Foo def say puts("Foo!") end end class

    Bar def say puts("Bar!") end end [Foo.new, Bar.new].each do |x| x.say() end
  34. μοΫλΠϐϯά class Foo: def say(self): print("Foo!") class Bar: def say(self):

    print("Bar!") for x in [Foo(), Bar()]: x.say() 1ZUIPO
  35. μοΫλΠϐϯά trait Talkable { def say(): Unit } class Foo

    extends Talkable { def say() = println("Foo!") } class Bar extends Talkable { def say() = println("Bar!") } def say(x: Talkable) = x.say() say(new Foo) say(new Bar) 4DBMB
  36. μοΫλΠϐϯά class Foo { def say() = println("Foo!") } class

    Bar { def say() = println("Bar!") } def say[E <: { def say() }](x: E) = x.say() say(new Foo) say(new Bar) 4DBMB
  37. NJYJO 3VCZ module Foo def say() puts("Foo!") end end module

    Bar include Foo def say() puts("Bar!") end end module Baz include Foo def say() puts("Baz!") end end class Qux include Bar include Baz def say() puts("Qux!") end end Qux.new.say()
  38. NJYJO 1ZUIPO class Foo: def say(self): print("Foo!") class Bar(Foo): def

    say(self): print("Bar!") class Baz(Foo): def say(self): print("Baz!") class Qux(Bar, Baz): def say(self): print("Qux!") Qux().say()
  39. NJYJO trait Foo { def say() = println("Foo!") } trait

    Bar extends Foo { override def say() = println("Bar!") } trait Baz extends Foo { override def say() = println("Baz!") } class Qux extends Bar with Baz { override def say() = println("Qux!") } new Qux say() 4DBMB
  40. 4DBMBͰ999͕͍ͨ͠ʂ

  41. 4DBMBͰ999͕͍ͨ͠ʂ

  42. ஥ؒʹͰ͖·ͨ͠Ͷʂ

  43. Ұॹʹઓ͓͏ʂ Ͳ͏͍͏ͱ͖ʹ࢖͑Δͷʁ Λ͓͑ͯ͞ΈΑ͏ʂ

  44. 4DBMBͷྑ͍ͱ͜Ζ ܕ҆શ ؔ਺ܕ ฒྻɾ෼ࢄ

  45. ؔ਺ܕʹ͠ͳ͍ɺܕ҆શʹ͠ͳ͍ ͱ͍͏ࣄ΋Ͱ͖·͢

  46. ࢖͍ํΛબͿࣄ͕Ͱ͖Δʂ

  47. ΍Γ͍ͨࣄʹ߹Θͤͯ ॊೈʹྗΛൃش

  48. ༐ऀλΠϓʂ

  49. ·ͱΊ جຊతͳ͜ͱ͓͑͞Α͏ʂ Α͋͘Δ࢖͍ํΛ͓͑͞Α͏ʂ ࢖͍ॴΛ͓͑͞Α͏ʂ

  50. ͜Θ͘ͳ͍Αʂ པΓʹͳΔ஥ؒͩΑʂ

  51. ͦͯ͠ͰΜͤͭ΁ʜ ͍ͤͪ͝ΐ͏͋Γ͕ͱ͏͍͟͝·ͨ͠