Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kolin Modifiers
Search
kissybnts
June 26, 2017
Programming
2
270
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
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
Scaling your build logic
antalmonori
1
100
rails newと同時に型を書く
aki19035vc
5
710
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
400
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
3
760
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
430
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
300
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
Rubyでつくるパケットキャプチャツール
ydah
0
180
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
160
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Statistics for Hackers
jakevdp
797
220k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Making the Leap to Tech Lead
cromwellryan
133
9k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.6k
Adopting Sorbet at Scale
ufuk
74
9.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
Music & Morning Musume
bryan
46
6.3k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Producing Creativity
orderedlist
PRO
343
39k
Building Adaptive Systems
keathley
38
2.4k
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