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
B2B SaaSあるある! 一括処理のエラーハンドリングをKotlinで関数型的に処理す...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
YuitoSato
June 23, 2023
Technology
2
730
B2B SaaSあるある! 一括処理のエラーハンドリングをKotlinで関数型的に処理する / Kotlin Functional Multi Error Handling
YuitoSato
June 23, 2023
Tweet
Share
More Decks by YuitoSato
See All by YuitoSato
「規約、知識、オペレーション」から考える中規模以上の開発組織のCursorルールの 考え方・育て方 / Cursor Rules for Coding Styles, Domain Knowledges and Operations
yuitosato
9
7.3k
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
2
3.6k
50人の組織でAIエージェントを使う文化を作るためには / How to Create a Culture of Using AI Agents in a 50-Person Organization
yuitosato
6
7.9k
Railway Oriented Programming を オニオンアーキテクチャに適用する by kotlin-result / Railway Oriented Programming in Onion Architecture by kotlin-result
yuitosato
5
1.5k
リファクタリングへの耐性が高いモデルベースの統合テストの紹介 / Model-Base Integration Test for Refactoring
yuitosato
7
3.7k
Expressing Business Logic with Types: Functional DDD for OOP
yuitosato
1
160
ビジネスロジックを「型」で表現するOOPのための関数型DDD / Functional And Type-Safe DDD for OOP
yuitosato
44
31k
Java21とKotlinの代数的データ型 & パターンマッチの紹介と本当に嬉しい使い方 / Algebraic Data Type in Java and Kotlin: Happy Use of Pattern Match
yuitosato
14
5.6k
ログラスの継続的ライブラリアップデートのWhyとHow / Why and How to Update Libraries Continuously in Loglass
yuitosato
0
520
Other Decks in Technology
See All in Technology
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
550
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
2
400
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
GitHub Issue Templates + Coding Agentで簡単みんなでIaC/Easy IaC for Everyone with GitHub Issue Templates + Coding Agent
aeonpeople
1
260
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
150
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.6k
pool.ntp.orgに ⾃宅サーバーで 参加してみたら...
tanyorg
0
640
OWASP Top 10:2025 リリースと 少しの日本語化にまつわる裏話
okdt
PRO
3
840
制約が導く迷わない設計 〜 信頼性と運用性を両立するマイナンバー管理システムの実践 〜
bwkw
3
1k
今こそ学びたいKubernetesネットワーク ~CNIが繋ぐNWとプラットフォームの「フラッと」な対話
logica0419
5
420
Cosmos World Foundation Model Platform for Physical AI
takmin
0
970
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
240
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
150
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.6k
We Are The Robots
honzajavorek
0
170
Thoughts on Productivity
jonyablonski
74
5k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Git: the NoSQL Database
bkeepers
PRO
432
66k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
55
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
The Language of Interfaces
destraynor
162
26k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
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