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
B2B SaaSあるある! 一括処理のエラーハンドリングをKotlinで関数型的に処理す...
Search
YuitoSato
June 23, 2023
Technology
790
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
B2B SaaSあるある! 一括処理のエラーハンドリングをKotlinで関数型的に処理する / Kotlin Functional Multi Error Handling
YuitoSato
June 23, 2023
More Decks by YuitoSato
See All by YuitoSato
「規約、知識、オペレーション」から考える中規模以上の開発組織のCursorルールの 考え方・育て方 / Cursor Rules for Coding Styles, Domain Knowledges and Operations
yuitosato
9
11k
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
2
5.7k
50人の組織でAIエージェントを使う文化を作るためには / How to Create a Culture of Using AI Agents in a 50-Person Organization
yuitosato
6
10k
Railway Oriented Programming を オニオンアーキテクチャに適用する by kotlin-result / Railway Oriented Programming in Onion Architecture by kotlin-result
yuitosato
5
1.8k
リファクタリングへの耐性が高いモデルベースの統合テストの紹介 / Model-Base Integration Test for Refactoring
yuitosato
7
4.2k
Expressing Business Logic with Types: Functional DDD for OOP
yuitosato
1
250
ビジネスロジックを「型」で表現するOOPのための関数型DDD / Functional And Type-Safe DDD for OOP
yuitosato
44
33k
Java21とKotlinの代数的データ型 & パターンマッチの紹介と本当に嬉しい使い方 / Algebraic Data Type in Java and Kotlin: Happy Use of Pattern Match
yuitosato
14
6k
ログラスの継続的ライブラリアップデートのWhyとHow / Why and How to Update Libraries Continuously in Loglass
yuitosato
0
600
Other Decks in Technology
See All in Technology
Vue で書く 空間コンピューティング、TresJS と WebXR を使ったXR デバイスのフロントエンド開発
hiranuma
0
120
reInvent2026stby LT00 "Change your life!"
shinichirokawano
1
400
演劇と私とスクラム
chinmo
0
160
Flutter Widget Previewerで始めるUIプレビューとVRTの自動化
sakusaku3939
0
150
AIをリアル世界に解き放つ 〜M5Stack×AIであなたのアイディアを手の平に〜
hamadakoji
1
580
顧客価値を追いかけたら、プライシングにたどり着いた
sansantech
PRO
2
1.1k
ドメインエキスパートは いかにして AI を使って プロダクト開発をするか
tatsuyashiraishi
1
220
Don't write the architecture only in the prompt.
neohsu
0
180
You Have Agency(サンキュー、Ruby)
snoozer05
PRO
3
470
AI駆動開発における開発環境のセキュリティの考え方
yamahiro
2
650
アカウント統制の健康診断
kenichinakamura
1
210
「作れる」と「リリースできる」の間にあったもの── PdMを外して見えた、PdMがやるべき仕事/Buildable ≠ Shippable: What Removing the PM Taught Me About the PM’s Job
yappli_developers
0
340
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
560
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
A designer walks into a library…
pauljervisheath
211
25k
The Invisible Side of Design
smashingmag
301
52k
Music & Morning Musume
bryan
48
7.5k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
370
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
650
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Building Applications with DynamoDB
mza
96
7.3k
Building AI with AI
inesmontani
PRO
1
1.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Transcript
1 ©2023 Loglass Inc. B2B SaaSあるある! 一括処理のエラーハンドリングをKotlinで関 数型的に処理する 2023.06.23 佐藤有斗(Yuiiitoto)
株式会社ログラス
2 ©2023 Loglass Inc. 自己紹介 佐藤有斗(Yuiiitoto) ログラス エンジニア 前回の発表
3 ©2023 Loglass Inc. ログラスについて 企業価値を向上する 経営管理クラウド
4 ©2023 Loglass Inc. ログラスについて(5秒) 企業価値を向上する 経営管理クラウド
5 ©2023 Loglass Inc. CSVで1000件ほど一括でデータを投入したい! その時に不正なデータがある場合は、複数まとめて 表示してくれ! 本日の要求
6 ©2023 Loglass Inc.
7 ©2023 Loglass Inc. 複数行でエラーがある
8 ©2023 Loglass Inc. 複数行でエラーがある 3行目: メールアドレスが空です 4行目: 性別にひらがなを利用することはできません
9 ©2023 Loglass Inc. 一つの行でも複数エラーがある
10 ©2023 Loglass Inc. 一つの行でも複数エラーがある 5行目: ユーザー名が空です 5行目: メールアドレスは100文字以下で入力してください 5行目:
性別「漢」は不正な値です
11 ©2023 Loglass Inc. 非常にめんどくさい
12 ©2023 Loglass Inc. 例外は一括処理が苦手 • 最初の不正なデータに出会ったら呼び出し元に戻ってしまう • Kotlinには検査例外がないのでコンパイルフェーズでエラーハンドリングを強制できない
13 ©2023 Loglass Inc. どうするか?
14 ©2023 Loglass Inc. 関数型エラーハンドリングで解決しよう
15 ©2023 Loglass Inc. 関数型エラーハンドリングとは • いわゆるScalaのEitherやRustにおけるResult • 例外ではなく型でエラーを表現する
16 ©2023 Loglass Inc. 詳しくはこちら(同僚のやつ)
17 ©2023 Loglass Inc. Kotlinで一括処理を エラーハンドリングする場合は Arrow.ktのEitherがおすすめ 今日特に頭の片すみに覚えてほしいこと
18 ©2023 Loglass Inc. Arrow.kt
19 ©2023 Loglass Inc. 実際のコードをみていくぞ! (詳しく説明する時間はない!)
20 ©2023 Loglass Inc. ユーザーの作成処理
21 ©2023 Loglass Inc. ユーザーの作成処理 • 失敗したら複数のエラー( List<IllegalArgumentException>) • 成功したらユーザーインスタンス(
User)
22 ©2023 Loglass Inc. これを再現する 5行目: ユーザー名が空です 5行目: メールアドレスは100文字以下で入力してください 5行目:
性別「漢」は不正な値です
23 ©2023 Loglass Inc. ユーザーの作成処理(ここは雰囲気理解でダイジョブ)
24 ©2023 Loglass Inc. ユーザーの作成処理(ここは雰囲気理解でダイジョブ) • 各フィールドに対してバリデーション処理
25 ©2023 Loglass Inc. ユーザーの作成処理(ここは雰囲気理解でダイジョブ) • バリデーション結果をつかってインスタンス作成
26 ©2023 Loglass Inc. 各バリデーションの処理 • 各バリデーションは失敗したら一つのエラー、成功したら値オブジェクトを返す
27 ©2023 Loglass Inc. 詳しくはjskmtさんのこちら(この次に発表するらしいです)
28 ©2023 Loglass Inc. 複数ユーザーの保存処理
29 ©2023 Loglass Inc. 複数ユーザーの保存処理
30 ©2023 Loglass Inc. 複数ユーザーの保存処理 • 複数の入力から複数のユーザーを作成 • 行番号をエラー文に埋め込みながら、エラーの内容を更新
31 ©2023 Loglass Inc. 複数ユーザーの保存処理 • 型をちょちょいってやる • 最後の最後は例外として投げる( SpringBootでよしなに処理させるため)
32 ©2023 Loglass Inc. これを再現する 3行目: メールアドレスが空です 4行目: メールアドレスは100文字以下で入力してく ださい
33 ©2023 Loglass Inc. 話せなかったおまけ(あとで話しましょう) • ログラスだと似た感じのライブラリの kotlin-result を使っている •
kotlin-resultだと zipOrAcummulateがなくて絶妙に使いにくい
34