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
260
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
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
220
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Arm移行タイムアタック
qnighy
0
320
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Remix on Hono on Cloudflare Workers
yusukebe
1
290
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Featured
See All Featured
Bash Introduction
62gerente
608
210k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Practical Orchestrator
shlominoach
186
10k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Building Adaptive Systems
keathley
38
2.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
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