Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
FSM DSL in Kotlin
Search
Tomoya Miwa
June 27, 2018
Programming
1.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
FSM DSL in Kotlin
Tomoya Miwa
June 27, 2018
More Decks by Tomoya Miwa
See All by Tomoya Miwa
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
8.6k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
750
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
510
できる!ComposeでCollapsingToolbar
tomoya0x00
0
1.1k
Compose の LazyColumn パフォーマンス改善で取り組んだこと
tomoya0x00
0
2.5k
ComposeのMutableStateってどうやってLocal Unit Testすれば良いの??
tomoya0x00
0
1.3k
意外と簡単?Navigation rail導入のお話
tomoya0x00
0
1.7k
Kotlin Coroutines Flow を触ってみた話し
tomoya0x00
2
920
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
320
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
1.2k
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
370
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
200
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
300
Railsバージョンを4倍にした話
optim
0
970
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
SODA - FACT BOOK(EN)
sodainc
1
220
protojson における文字化けの扱い
kazuki1023
0
220
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
880
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Designing Experiences People Love
moore
143
24k
A better future with KSS
kneath
240
18k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
610
Why Our Code Smells
bkeepers
PRO
340
58k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
Writing Fast Ruby
sferik
630
63k
The Curious Case for Waylosing
cassininazir
1
610
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Transcript
FSM DSL in Kotlin tomoya0x00 Kotlin Developers Meetup
About me tomoya0x00 Twitter, GitHub, Qiita Android, Embedded system, BLE/BT,
iOS DeNA Co., Ltd. Automotive Business Unit.
Everyone
You want to make DSL by yourself?
I want to FSM DSL in Kotlin FSM is nite
state machine.
Why FSM? Avoid confusion caused by multiple ag management Easy
to test
And, I want to support composite states
Example
Simple smart lock for bike sharing
I am developing a Proof-of-Concept
DSL Example val sm = stateMachine(initial = MyState.NotLoaned) { state(MyState.NotLoaned)
{ edge(MyEvent.PressRental, next = MyState.Lock) } state(MyState.OnLoan, entry = { println("turnOnRentalLed") }, exit = { println("turnOffRentalLed") }) { state(MyState.Lock) { edge(MyEvent.PressReturn, next = MyState.NotLoaned) edge(MyEvent.PressUnLock, next = MyState.UnLock) } state(MyState.UnLock) { edge(MyEvent.PressLock, next = MyState.Lock) } } }
Let's run! val next = sm.dispatch(MyEvent.PressRental) assert(next).isEqualTo(MyState.Lock) result: turnOnRentalLed next
== MyState.Lock
Internal
Generate the tree of states DSL Tree of states
DSL internal fun stateMachine( initial: BaseState, init: StateMachine.() -> Unit
): StateMachine = StateMachine(initial = initial) .apply(init)
Problem
Search processing is executed for each dispatch
When press return in Lock state Find route to NotLoaned
state from Lock state
When press return in Lock state Find route to NotLoaned
state from Lock state
When press return in Lock state Find route to NotLoaned
state from Lock state
When press return in Lock state Find route to NotLoaned
state from Lock state
When press return in Lock state Find route to NotLoaned
state from Lock state
When press return in Lock state Execute entry/exit on route
Solution
StateMachine.Builder fun stateMachine( initial: BaseState, init: StateMachine.Builder.() -> Unit ):
StateMachine = StateMachine.Builder(initial = initial) .apply(init).build()
Generate transition map in build() state event actions next NotLoaned
PressRental [OnLoan.entry] Lock Lock PressReturn [OnLoan.exit] NotLoaned Lock PressUnLock [] UnLock UnLock PressLock [] Lock
But, not implemented yet... to be available soon!
Any Idea? Tree search algorithm when creating transition map, if
you have any good idea, please let me know!
Waiting for your suggestions︕ https://github.com/tomoya0x00/fsm-dsl- kotlin-poc
Thank you!