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

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

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

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

Tatsuya Iwamatsu

December 22, 2017
Tweet

More Decks by Tatsuya Iwamatsu

Other Decks in Programming

Transcript

  1. ࢛ଇԋࢉ 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
  2. ม਺ɾ഑ྻ 3VCZ 1ZUIPO 4DBMB foo = [1, 2, 3] print(foo)

    foo = [1, 2, 3] print(foo) val foo = List(1, 2, 3) print(foo)
  3. ϝιου 3VCZ 1ZUIPO 4DBMB def foo print("hello") end foo() def

    foo(): print("hello") foo() def foo = { println("hello") } foo()
  4. 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!") }
  5. 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 }
  6. Ϋϥε 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()
  7. ίϨΫγϣϯૢ࡞ 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)
  8. μοΫλΠϐϯά 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
  9. μοΫλΠϐϯά class Foo: def say(self): print("Foo!") class Bar: def say(self):

    print("Bar!") for x in [Foo(), Bar()]: x.say() 1ZUIPO
  10. μοΫλΠϐϯά 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
  11. μοΫλΠϐϯά 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
  12. 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()
  13. 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()
  14. 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