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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
YuitoSato
June 23, 2023
Technology
780
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
10k
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
2
5.6k
50人の組織でAIエージェントを使う文化を作るためには / How to Create a Culture of Using AI Agents in a 50-Person Organization
yuitosato
6
9.9k
Railway Oriented Programming を オニオンアーキテクチャに適用する by kotlin-result / Railway Oriented Programming in Onion Architecture by kotlin-result
yuitosato
5
1.7k
リファクタリングへの耐性が高いモデルベースの統合テストの紹介 / Model-Base Integration Test for Refactoring
yuitosato
7
4.1k
Expressing Business Logic with Types: Functional DDD for OOP
yuitosato
1
240
ビジネスロジックを「型」で表現する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
5.9k
ログラスの継続的ライブラリアップデートのWhyとHow / Why and How to Update Libraries Continuously in Loglass
yuitosato
0
590
Other Decks in Technology
See All in Technology
TiDBファミリーにDWHが新登場!! TiDB最新情報 / TiDB update 202609
yoshiakiyamasaki
0
120
20260929_AmazonGuardDutyの検出通知メールにAWS DevOpsAgentの調査結果を追加する
yhana
1
230
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
430
人にやさしく、AIにやさしく、書き手を選ばないIaCのガードレール再考 / Rethinking IaC Guardrails for Humans and AI Alike
kohbis
5
1.4k
猫でもわかるKiro Web
kentapapa
1
120
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.3k
AIに賢く動いてもらうためのコンテキスト〜Snowflake女子会 vol.8
snowwmn0824
0
180
企業の現実世界をグラフで写し取る
sansantech
PRO
0
110
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
290
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
7
780
AI臭い文章とは何なのか
nasuvitz
4
1.9k
Lambda MicroVMsは常駐サーバーの代わりに なるか? Kiro Crew を動かして検証してみた / Kiro Crew on Lambda MicroVMs
k_adachi_01
2
270
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
25k
Producing Creativity
orderedlist
PRO
348
41k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Paper Plane
katiecoart
PRO
4
53k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Designing for humans not robots
tammielis
254
26k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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