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
740
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
500
できる!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
910
Android for Carsのお話し
tomoya0x00
1
1.1k
Other Decks in Programming
See All in Programming
パーソナライズPodcastを作った話
repunit11
0
130
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
980
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
22
22k
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
350
golang-bob.pdf
iwatsukayura
0
130
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.3k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
1
220
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
170
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
Java 27新機能 / Java 27 new features
kishida
2
220
パスワード再設定メールのURLについて知っておこう
uyuki234
0
140
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Navigating Team Friction
lara
192
16k
Facilitating Awesome Meetings
lara
57
7.2k
Building an army of robots
kneath
307
47k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Automating Front-end Workflow
addyosmani
1369
210k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Product Roadmaps are Hard
iamctodd
55
13k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Paper Plane (Part 1)
katiecoart
PRO
2
11k
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!