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
自宅サーバと脆弱性
masakiokuda
1
120
cdk deployとcdkd deploy、実際にデプロイして5倍速近くの差を実測した
yama3133
1
110
Adversary Infrastructure Hunting101
disconinja
0
160
顧客価値を追いかけたら、プライシングにたどり着いた
sansantech
PRO
2
1.1k
演劇と私とスクラム
chinmo
0
160
Devin プロモコードの受け取りと適用(2026.10.27)
kinopeee
1
660
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
250
なぜAI時代に技術記事を書くのか?どう書くのか? 〜bunの場合〜
kworkdev
PRO
0
160
AI駆動開発におけるハーネスエンジニアリングの勘所
tsukuboshi
1
820
Claude Codeから見る、エンジニアの世界の変容とその先
oikon48
7
4.6k
Vue.jsのGitHubから学ぶ意思決定
yut0naga1_fa
1
320
ビジネス部門からPOを迎えての半年間の進歩と課題
zozotech
PRO
0
150
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
610
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
640
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
290
Crafting Experiences
bethany
1
390
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Accessibility Awareness
sabderemane
1
260
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
650
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
340
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
320
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