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
690
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
470
できる!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
net-httpのHTTP/2対応について
naruse
0
450
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
570
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
250
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
730
Claspは野良GASの夢をみるか
takter00
0
170
Oxcを導入して開発体験が向上した話
yug1224
4
290
Inside Stream API
skrb
1
650
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
500
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
220
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
650
Agentic UI
manfredsteyer
PRO
0
110
Featured
See All Featured
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
170
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
The Limits of Empathy - UXLibs8
cassininazir
1
350
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Thoughts on Productivity
jonyablonski
76
5.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
600
A Soul's Torment
seathinner
6
2.9k
Paper Plane (Part 1)
katiecoart
PRO
0
8.5k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
440
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Done Done
chrislema
186
16k
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!