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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
YuitoSato
June 23, 2023
Technology
750
2
Share
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
8.5k
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
2
4.4k
50人の組織でAIエージェントを使う文化を作るためには / How to Create a Culture of Using AI Agents in a 50-Person Organization
yuitosato
6
8.7k
Railway Oriented Programming を オニオンアーキテクチャに適用する by kotlin-result / Railway Oriented Programming in Onion Architecture by kotlin-result
yuitosato
5
1.6k
リファクタリングへの耐性が高いモデルベースの統合テストの紹介 / Model-Base Integration Test for Refactoring
yuitosato
7
3.9k
Expressing Business Logic with Types: Functional DDD for OOP
yuitosato
1
190
ビジネスロジックを「型」で表現する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.7k
ログラスの継続的ライブラリアップデートのWhyとHow / Why and How to Update Libraries Continuously in Loglass
yuitosato
0
530
Other Decks in Technology
See All in Technology
#jawsugyokohama 100 LT11, "My AWS Journey 2011-2026 - kwntravel"
shinichirokawano
0
310
Rapid Start: Faster Internet Connections, with Ruby's Help
kazuho
2
140
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
1
320
Revisiting [CLS] and Patch Token Interaction in Vision Transformers
yu4u
0
310
🀄️ on swiftc
giginet
PRO
0
390
20260415_生成AIを専属DSに_自動レポート作成_ハンズオン_交通事故データ
doradora09
PRO
0
110
扱える不確実性を増やしていく - スタートアップEMが考える「任せ方」
kadoppe
0
240
Snowflake Intelligence導入で 分かった活用のコツ
wonohe
0
110
「責任あるAIエージェント」こそ自社で開発しよう!
minorun365
9
1.5k
インフラを Excel 管理していた組織が 3 ヶ月で IaC 化されるまで
geekplus_tech
3
210
The Journey of Box Building
tagomoris
4
290
ハーネスエンジニアリングの概要と設計思想
sergicalsix
9
3.9k
Featured
See All Featured
We Are The Robots
honzajavorek
0
210
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
710
The SEO Collaboration Effect
kristinabergwall1
0
420
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
Being A Developer After 40
akosma
91
590k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
330
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Fireside Chat
paigeccino
42
3.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
170
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
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