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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
120
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
640
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
net-httpのHTTP/2対応について
naruse
0
480
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
4
840
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
180
Agentic UI
manfredsteyer
PRO
0
160
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
130
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.6k
OSもどきOS
arkw
0
560
Webフレームワークの ベンチマークについて
yusukebe
0
170
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
420
Designing for humans not robots
tammielis
254
26k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
140
Music & Morning Musume
bryan
47
7.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
230
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
430
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
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!