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
Ankoは甘くて美味しい〜Ankoに見るKotlinの表現力〜 #gunosybeer
Search
Taro Nagasawa
December 08, 2015
Programming
0
1.6k
Ankoは甘くて美味しい〜Ankoに見るKotlinの表現力〜 #gunosybeer
エムスリー x Gunosy Beer bash!で発表した資料です
Taro Nagasawa
December 08, 2015
Tweet
Share
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
370
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.1k
#Ubie 狂気の認知施策と選考設計
ntaro
13
12k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.1k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.3k
Kotlinでサーバサイドを始めよう!
ntaro
1
920
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2.6k
Kotlin Contracts #m3kt
ntaro
4
3.8k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
430
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
360
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
260
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Contemporary Test Cases
maaretp
0
140
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
510
110k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Building Adaptive Systems
keathley
38
2.3k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Speed Design
sergeychernyshev
25
620
Faster Mobile Websites
deanohume
305
30k
Transcript
Ankoͯ͘ඒຯ͍͠ ʙAnkoʹݟΔKotlinͷදݱྗʙ ΤϜεϦʔY(VOPTZ#FFSCBTIʂ HVOPTZCFFS ᖒଠ!OHTX@UBSP
ࣗݾհ w ᖒଠ!OHTX@UBSP w "OESPJEΤϯδχΞ w ,PUMJOΤϰΝϯδΣϦετ ࣗশ w
ࡀɺֈ࠲ɺͱ͕େ͖
Kotlinͱ w +FU#SBJOT։ൃͷ+7.ݴޠ w "OESPJEαϙʔτ w ൃදɺ·ͩϕʔλ൛ w "OESPJE+BWB͔Β,PUMJOΓ͑ϫϯνϟϯ w
࠷ۙɺհهࣄ͕ཚཱͯ͠ΔͷͰͦͪΒࢀর
Ankoͱ w ,PUMJOͰهड़͞Εͨ"OESPJEϥΠϒϥϦ w +FU#SBJOT։ൃʢઆಘྗɾ҆৺ײ͕͋Δʣ w ओʹ6*ΛΈཱͯΔ%4-
UIΛΈཱͯΔDSL w جຊతʹ"OESPJEͰ9.-Ͱ6*Λදݱ͢Δ w ࠶ར༻ੑɺ҆શੑɺύϑΥʔϚϯεͷ໘Ͱෆར w ͱ͍͑ίʔυͰ໋ྩతʹ6*Λߏங͢Δͷμα Πʢ4XJOHΈ͍ͨͳΠϝʔδʣ w %4-Ͱએݴతʹ6*Λߏங͢Δ
ʢ+BWB'94DSJQUΈ͍ͨͳΠϝʔδʣ
ඪ४APIͰΰϦΰϦΔ val act = this! val layout = LinearLayout(act)! layout.orientation
= LinearLayout.VERTICAL! val name = EditText(act)! val button = Button(act)! button.text = "Say Hello"! button.setOnClickListener {! Toast.makeText(act,! "Hello, ${name.text}!”,! Toast.LENGTH_SHORT).show()! }! layout.addView(name)! layout.addView(button)
AnkoͰDSL verticalLayout {! val name = editText()! button("Say Hello") {!
onClick {! toast("Hello, ${name.text}!”)! }! }! }
Ͳ͏ಈ͍͍ͯΔͷ͔ There is no .
ϥϜμࣜ Lambda Expression
ߴ֊ؔͱϥϜμࣜ // ҾʹAΛऔͬͯBΛฦؔ͢fΛҾʹऔΔؔ! fun <A, B> convert(target: A,! f: (A)->B)
= f(target)! ! convert(1, { x: Int -> x * 2 }) //=> 2! convert(2, { x -> x * 2}) //=> 4! convert(3, { it * 2 }) //=> 6! convert(4) { it * 2 } //=> 8
֦ுؔ Extension Function
֦ுؔ fun String.hello() = “Hello, $this”! ! “world”.hello() //=> “Hello,
world”
֦ுؔ × ϥϜμࣜ fun <A, B> A.convert(f: (A)->B) = f(this)!
! 3.convert({ x: Int -> x * 2}) //=> 6! 3 convert { it * 2 } //=> 6
Anko class MainActivity : Activity() {! override fun onCreate(savedInstanceState: Bundle?)
{! super.onCreate(savedInstanceState)! ! verticalLayout {! val name = editText()! button("Say Hello") {! onClick { toast("Hello, ${name.text}!") }! }! }! }! }
Anko class MainActivity : Activity() {! override fun onCreate(savedInstanceState: Bundle?)
{! super.onCreate(savedInstanceState)! ! verticalLayout {! val name = editText()! button("Say Hello") {! onClick { toast("Hello, ${name.text}!") }! }! }! }! } "DUJWJUZͷ֦ுؔ UIJT͕লུ͞ΕͯΔ
Anko class MainActivity : Activity() {! override fun onCreate(savedInstanceState: Bundle?)
{! super.onCreate(savedInstanceState)! ! verticalLayout {! val name = editText()! button("Say Hello") {! onClick { toast("Hello, ${name.text}!") }! }! }! }! } ͜ͷUIJT WFSUJDBM-BZPVU
Anko class MainActivity : Activity() {! override fun onCreate(savedInstanceState: Bundle?)
{! super.onCreate(savedInstanceState)! ! this.verticalLayout {! val name = this.editText()! this.button(“Say Hello") {! onClick { toast("Hello, ${name.text}!") }! }! }! }! } UIJT͕ผͷͷΛࢦ͢ Կނ͔ʁ
֦ுؔΛҾʹऔΔߴ֊ؔ class Builder { fun foo() {} }! ! fun
build(f: Builder.() -> Unit) {! Builder().f()! }! ! build {! foo()! }
Կ͕خ͍͠ͷ͔ verticalLayout {! button(“foo”)! verticalLayout {! button(“bar”)! verticalLayout {! button(“baz”)!
}! }! }
Կ͕خ͍͠ͷ͔ verticalLayout {! button(“foo”)! verticalLayout {! button(“bar”)! verticalLayout {! button(“baz”)!
}! }! } ֊ߏΛදݱͰ͖Δ ϝιουͷείʔϓ ΛߜΕΔ ܕ҆શ OVMM҆શ
XMLͰฤू͢Δͱ ը໘ϓϨϏϡʔ ݟΕΔ͡ΌΜʁ
None
ͦΕɺAnkoͰ Ͱ͖·͢ʂ
None
Θͳ͍खͳ͍
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠