operandoOS
December 09, 2016
220

# Kotlinでマッチョ💪💪💪💪💪する話

Kotlinでマッチョ💪💪💪💪💪する話

Retty Tech Cafe #8
https://retty.connpass.com/event/45628/

## operandoOS

December 09, 2016

## Transcript

1. KotlinͰ
Ϛονϣ
͢Δ࿩
Retty Tech Cafe #8

Shinobu Okano
@operandoOS
Mercari, Inc.
Souzoh, Inc.

3. ຖ೔30෼ Kotlin΍ͬͯ·͢
• ࡶʹࡶʹϝϞΛ࢒ͯ͠·͢
• http://hack-it-iron.hatenablog.com/archive/
category/Kotlin

4. Tuple
ෳ਺ݸͷ஋Λ૊Έʹͯ͠·ͱΊͨ΋ͷ

5. Α͏͸
Ұ࣌తͳείʔϓͰෳ਺ݸͷσʔλͷ૊Έ߹Θ͕ͤ
ཉ͍͚͠ͲɺClassΛఆٛ͢Δ΄ͲͰ΋ͳ͍ͳʔ
ͬͯ࣌ʹ༗ޮ

6. Guild
https://github.com/operando/Guild/
Simple java tuples.

7. ͳͥTuple͕ඞཁ͔ͩͬͨ
• Android + JSON-RPC
• http://www.slideshare.net/shinobuokano7/
android-jsonrpc
• ཧ༝ॻ͍ͯ͋Δ͔΋ʁ

8. KotlinͷPair
val pair = 1 to "pair"
println(pair.first) // 1
println(pair.second) // pair

9. Triple΋͋ΔΑ
val triple = Triple(1, true, "Triple")
println(triple.first) // 1
println(triple.second) // true
println(triple.third) // Triple

10. ͜ΕΛΈ͓ͯ΋ͬͨ

11. ͜͏ॻ͚ͳ͍ͷʁ
val triple = 1 to true to "Triple"

12. ͜͏ॻ͚ͳ͍ͷʁ
val triple = A to B to C

13. ͦͷ··Ͱ͸ॻ͚ͳʔ͍
• Pair in Pairʹͳͬͯ͠·͏
• Pair,C>
• ((1,true)"Triple")

14. ͳʔΜͩɺΧοίΘΔ͍

15. ͦ΋ͦ΋ Pairͷtoͬͯ
Ͳ͏ͳͬͯΔΜͩ?

16. ͦ΋ͦ΋ PairͷtoͬͯͲ͏ͳͬͯΔΜͩ?
public infix fun .to(that: B)
: Pair = Pair(this, that)

17. ͳΔ΄Ͳ

18. ͍΍ɺ·ͯΑ

19. ಉ͡Α͏ʹ֦ுؔ਺
࡞Ε͹Ͱ͖Δ͔☺

20. Pair͔ΒTripleΛ࡞Δ֦ுؔ਺Λॻ͍ͯΈͨ
infix fun Pair.to(that: C)
: Triple =
Triple(this.first, this.second, that)

21. ͡ΌtoͰͭͳ͛ͯ
ॻ͍ͯΈΑ͏

22. ͡ΌtoͰͭͳ͛ͯॻ͍ͯΈΑ͏
val triple = 1 to true to "Triple"
println(triple.first) // 1
println(triple.second) // true
println(triple.third) // Triple
println(triple.javaClass) // class kotlin.Triple

23. Ͱ͖ͨ☺

24. ΋ͬͱϚοεϧ
͍ͨ͠Ͱ͠ΐʁ

25. 4ͭͷ஋Λ࣋ͭ
Tuple QuartetΛ࡞Ζ͏

26. 4ͭͷ஋Λ࣋ͭTuple QuartetΛ࡞Ζ͏
class Quartet(
val first: F,
val second: S,
val third: T,
val fourth: FO,) {
override fun toString(): String {
return "Quartet(first=\$first, second=\$second,
third=\$third, fourth=\$fourth)"
}
}

27. toͭͳ͗ͰQuartetΛ
࡞ΕΔΑ͏ʹ͢Δ

28. Triple͔ΒQuartetΛ࡞Δ֦ுؔ਺Λॻ͘
infix fun Triple.to(that: D):
Quartet =
Quartet(this.first, this.second, this.third, that)

29. Quartet࢖ͬͯΈΑ͏
val quartet = 1 to 10L to true to "quartet"
println(quartet.first) // 1
println(quartet.second) // 10
println(quartet.third) // true
println(quartet.fourth) // quartet

30. ΋ͬͱϚοεϧ
΄͘͠ͳ͍??

31. 5ͭͷ஋Λ࣋ͭ
Tuple QuintetΛ࡞Ζ͏

32. 5ͭͷ஋Λ࣋ͭTuple QuintetΛ࡞Ζ͏
class Quintet(
val first: F,
val second: S,
val third: T,
val fourth: FO,
val five: FI) {
override fun toString(): String {
return "Quintet(first=\$first, second=\$second,
third=\$third, fourth=\$fourth, five=\$five)"
}
}

33. ͸͍͸͍ɺtoΛͭͳ͛ͯ
ॻ͍ͯ࡞Γ͍ͨΑͶ

34. ͸͍͸͍ɺ֦ுؔ਺֦ுؔ਺
infix fun Quartet.to(that: E):
Quintet = Quintet(this.first, this.second,
this.third, this.fourth, that)

35. Quintet࢖ͬͯΈΑ͏
val quintet = 1 to 10L to true to LocalDateTime.now() to "quintet"
println(quintet.first) // 1
println(quintet.second) // 10
println(quintet.third) // true
println(quintet.fourth) // 2016-12-09T19:45:38.959
println(quintet.five) // quintet

36. Libraryʹ͠·ͨ͠

37. Guild Kotlin
https://github.com/operando/Guild/
tree/master/guild-kotlin
͍͔ͭjCenterͱ͔ʹ͋͛·ʔ͢