Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kolin Modifiers
Search
kissybnts
June 26, 2017
Programming
2
290
Kolin Modifiers
「KotlinのLT会!Kotlin入門者の集い」で発表したやつの全部込み版です。
kissybnts
June 26, 2017
Tweet
Share
More Decks by kissybnts
See All by kissybnts
JavaエンジニアからみたVapor
kissybnts
0
180
Other Decks in Programming
See All in Programming
社内オペレーション改善のためのTypeScript / TSKaigi Hokuriku 2025
dachi023
1
130
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
8
11k
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
770
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
680
20251127_ぼっちのための懇親会対策会議
kokamoto01_metaps
2
240
非同期処理の迷宮を抜ける: 初学者がつまづく構造的な原因
pd1xx
0
180
Duke on CRaC with Jakarta EE
ivargrimstad
0
310
データファイルをAWSのDWHサービスに格納する / 20251115jawsug-tochigi
kasacchiful
2
100
最新のDirectX12で使えるレイトレ周りの機能追加について
projectasura
0
310
OSS開発者の憂鬱
yusukebe
15
12k
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
200
競馬で学ぶ機械学習の基本と実践 / Machine Learning with Horse Racing
shoheimitani
14
14k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
11
950
GitHub's CSS Performance
jonrohan
1032
470k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
A Modern Web Designer's Workflow
chriscoyier
697
190k
A designer walks into a library…
pauljervisheath
210
24k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
Fireside Chat
paigeccino
41
3.7k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Unsuck your backbone
ammeep
671
58k
Transcript
Kolin Modifiers ,PUMJOͷ-5ձʂ,PUMJOೖऀͷू͍
Name: Company: Role: Language: Kotlin: ͖ͩ͠ ServerSideEngineer, BridgeEngineer Java 1.0͘Β͍͔Β
None
None
,PUMJOʹؔʹ͚ͭΔ͜ͱ͕Ͱ͖Δ .PEJpFS म০ࢠ ͕͍Ζ͍Ζ͋Δ
‣ infix ‣ inline ‣ noinline ‣ crossinline ‣ reified
‣ tailrec
͜ΕΒΛઆ໌͠·͢
7JTJCJMJUZ.PEJpFSTάά͍ͬͯͩ͘͞
infix
Ҿ͕ͭͷϝιουΛ ׅހͳ͠Ͱ͑ΔΑ͏ʹ͢Δ
None
infix Modifier
StringΫϥεͷ֦ுؔ
ҾҰͭ
͜Μͳ෩ʹ͑Δ
w ϝϯόؔ·֦ͨுؔ w Ҿ͕ͭ w infixΛؔʹ͚ͭΔ ༻݅
ͪΖΜͭͳ͛ͯ͑Δ
͜ΕΛ
͜͏ͯ͠
͜ΕΛ
͜͏͢Δ
ͪͳΈʹ
͜ΕͩΊ
͜Ε0,
inline
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
None
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
'VODUJPOMJUFSBMͱʁ
None
ແ໊ؔ
ϥϜμࣜͰ͞ΕΔ ؔͷ͜ͱ
ΠϯϥΠϯల։ͱʁ
؆୯ͳൺֱͰઆ໌
None
StringΫϥεͷ֦ுؔ
StringΛҾʹͱͬͯStringΛฦؔ͢
ҾͷؔΛ࣮ߦͯ͠ɺtoUpperCase()ͯ͠ฦ͢
inline Modifier
ͦΕҎ֎Ұॹ
None
݁Ռಉ͡
None
ͦΕͧΕ࣮ߦ࣌ʹͲ͏ͳΔͷ͔ʁ
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
SFDFJWFSͷΛ֨ೲ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
֦ுؔͱಉ໊͡લͷ͕ؔ࡞͞ΕݺΕΔ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ୈҰҾʹSFDFJWFS inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ؔΦϒδΣΫτͷΠϯελϯεΛ࡞ׂͯ͠Γͯ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
/* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
JOWPLFͱ͍͏ϝιουΛͭ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
தϥϜμࣜͰͨ͠ॲཧ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨ͠ΫϥεͰ͢ */ inlineແ͠
/* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
ϥϜμࣜͰͨ͠ॲཧΛͭΠϯελϯε /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
ϥϜμࣜͰͨ͠ॲཧΛ࣮ߦ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
toUpperCase()Λͯ͠ฦ͢ /* આ໌ͷͨΊʹ؆ུతʹهड़ͨؔ͠Ͱ͢ */ inlineແ͠
inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ϝιουݺͼग़͠ͷίετ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
Πϯελϯεੜͷίετ inlineແ͠ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
None
/* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠આ໌͠·͢ */ inline͋Γ
inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ಉ͡ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ϥϜμࣜͰͨ͠ॲཧ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
toUpperCase()ͯ͠ऴΘΓ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
ΠϯϥΠϯల։ inline͋Γ /* ཧղ͍͢͠Α͏ʹKotlinͰ؆ུԽͯ͠هड़͍ͯ͠·͢ */
'VODUJPOMJUFSBMΛΠϯϥΠϯల։͢Δ͜ͱͰ ࣮ߦ࣌ͷΦʔόʔϔουΛݮΒ͠ ύϑΥʔϚϯεΛ্ͤ͞Δ
Πϯελϯεͷੜίετ ϝιουݺͼग़͠ͷίετ
Πϯελϯεͷੜίετ ϝιουݺͼग़͠ͷίετ
None
ؔ࿈͢Δಛ
ϥϜμࣜͷதͰreturnΛͬͯ ݺͼग़͠ݩͷؔΛൈ͚Δ͜ͱ͕Ͱ͖Δ
inlineͳ͠
None
ίϯύΠϧΤϥʔ
͜ͷதͰݺͼग़͠ݩͷ͔ؔΒൈ͚Α͏ͱ͢Δ
inline͋Γ
None
σϑΥϧτͰinlineʹͳΒͳ͍ͷͳͥʜ
ΠϯϥΠϯԽ͢Δ͕ؔେ͖͍ͱ ੜ͞ΕΔίʔυ͕ංେԽ͢ΔՄೳੑ͕͋Δ
ϥϜμࣜͰͷreturn͕ޡղΛট͖͍͢ /* ͜Εओ؍Ͱ͢ */
noinline
ΠϯϥΠϯԽ͠ͳ͍ؔΛࢦఆͰ͖Δ
None
noinline Modifier
͜ͷؔΠϯϥΠϯల։͞Εͳ͍
ͬͪ͜ͷؔΠϯϥΠϯల։͞ΕΔ
crossinline
ҾͷؔΛinlineؔҎ֎ͷจ຺Ͱ ࣮ߦͰ͖ΔΑ͏ʹ͢Δ
None
None
͞ΕͨؔΛ
Invokableܕͷಗ໊Ϋϥεͷ
injectedFunction()ͱ͍͏ϝιουͷ࣮ʹ͍͍ͨ
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" }
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } injectedFunction()ͱ͍͏abstractϝιου
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } invoke()ͱ͍͏ϝιουͷதͰ
abstract class Invokable { fun invoke(arg: String): String { val
before = doSomethingBefore(arg) val injected = injectedFunction(before) return doSomethingAfter(injected) } abstract fun injectedFunction(arg: String): String fun doSomethingBefore(arg: String) = "before$arg" fun doSomethingAfter(arg: String) = "${arg}after" } ͏
ίϯύΠϧΤϥʔ
None
None
crossinline Modifier
͑Δ
reified
inlineؔͰ ܕύϥϝʔλʹΞΫηεՄೳʹ͢Δ
ܕύϥϝʔλ
ClassΫϥεΛҾʹऔΔ
ಉ͡ܕͷListΛฦ͢
͞ΕͨํʹΑͬͯॲཧΛ͚Δ
None
None
None
inline Modifier
reified Modifier
Ҿແ͠
ܕύϥϝʔλ͕ར༻Ͱ͖Δ
None
ܕΛએݴ͢Δ
Ҿͳ͠Ͱ࣮ߦ
ܕΛਪ͢Δ
ܕΛࢦఆ࣮ͯ͠ߦ
None
None
ActivityΫϥεͷ֦ுؔ
reifiedΛ͚ͭͯΞΫηεՄೳʹ
Activity.findViewById()ͷΓΛ
ܕύϥϝʔλͰࢦఆ͞ΕΔܕʹΩϟετͯ͠ฦ͢
ܕએݴΛ͢Δ
ຖճΩϟετΛॻ͘ඞཁ͕ͳ͘ͳΔ
None
tailrec
ඌ࠶ؼͳؔͷ࣮ߦΛ࠷దԽ͢Δ
ඌ࠶ؼ
wؔܕݴޠͰΑ͘ݟΔελΠϧ wϧʔϓͷॲཧΛସ͢Δ wؔͷ࠷ޙʹࣗΛݺͼग़͢
None
tailrec Modifier
දࣔ͢Δϝοηʔδ
දࣔ͢Δճ
ճ͕0ҎԼͷ࣌return
ϝοηʔδΛදࣔͯ͠
ճΛݮΒͯࣗ͠Λݺͼग़͢
tailrecແ͠ͰίϯύΠϧͰ͖Δ
ͳʹ͕ҧ͏ͷ͔ʁ
tailrecແ͠ͷ߹
None
ίϯύΠϧ͞Εͯ΄΅ಉ͡
4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕ߴ͍
None
tailrec͋Γͷ߹
while͕࣮ߦ͞ΕΔ
ࣗΛݺͼग़͞ͳ͍
4UBDL0WFS'MPX͕ى͖ΔՄೳੑ͕͘ͳΔ
None
4UBDL0WFS'MPX͕ى͖ͳ͍Θ͚Ͱͳ͍
Ҏ্
&OKPZ,PUMJO