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
FSM DSL in Kotlin
Search
Tomoya Miwa
June 27, 2018
Programming
1.2k
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.2k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
700
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
480
できる!ComposeでCollapsingToolbar
tomoya0x00
0
1.1k
Compose の LazyColumn パフォーマンス改善で取り組んだこと
tomoya0x00
0
2.5k
ComposeのMutableStateってどうやってLocal Unit Testすれば良いの??
tomoya0x00
0
1.2k
意外と簡単?Navigation rail導入のお話
tomoya0x00
0
1.6k
Kotlin Coroutines Flow を触ってみた話し
tomoya0x00
2
900
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
Contextとはなにか
chiroruxx
1
390
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
自作OSでスライド発表する
uyuki234
1
3.7k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
240
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.7k
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
270
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
380
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.7k
関数型プログラミングのメリットって何だろう?
wanko_it
0
140
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
160
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
200
Featured
See All Featured
Building Adaptive Systems
keathley
44
3.1k
My Coaching Mixtape
mlcsv
0
170
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
420
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.6k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
410
Technical Leadership for Architectural Decision Making
baasie
3
430
Mobile First: as difficult as doing things right
swwweet
225
10k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
4 Signs Your Business is Dying
shpigford
187
22k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
310
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
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!