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
20250624 関数型DDD 13
Search
saka
December 24, 2025
1
0
Share
20250624 関数型DDD 13
saka
December 24, 2025
More Decks by saka
See All by saka
20250304 関数型DDD 6
sakatttttta
0
17
20241219 Github Actionsの面倒いところ
sakatttttta
0
3
20250109 関数型
sakatttttta
0
3
20250116 関数型DDD 2
sakatttttta
0
4
20250123 関数型DDD 3
sakatttttta
0
2
20250206 関数型DDD 4
sakatttttta
0
1
20250213 関数型DDD 4
sakatttttta
0
2
20250220 Hono カスタムfetch
sakatttttta
0
1
20250225 関数型DDD 5
sakatttttta
0
1
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
210
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
250
The Language of Interfaces
destraynor
162
26k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
95
The World Runs on Bad Software
bkeepers
PRO
72
12k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
170
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Bash Introduction
62gerente
615
210k
Transcript
DDD
ResultͷϦετ
ݱࡏͷϦετ
None
Γํʢskipʣ
None
reduceRightޙΖ͔Βॲཧ
ඇಉظ
ResultͱҰॹ
AsyncResultΛ࡞ͬͯ͋͛Δ type CheckAddressExists = UnvalidatedAddress -> AsyncResult<CheckedAddress, AddressValidationError>
γϦΞϥΠζ
None
Result let workflowWithSerialization jsonString = jsonString |> deserializeInputDto // JSON͔ΒDTO
|> inputDtoToDomain // DTO͔ΒυϝΠϯΦϒδΣΫτ |> workflow // υϝΠϯͷίΞϫʔΫϑϩʔ |> outputDtoFromDomain // υϝΠϯΦϒδΣΫτ͔ΒDTO |> serializeOutputDto // DTO͔ΒJSON // ࠷ऴग़ྗผͷJsonString
λϓϧ
/// ରԠ͢ΔDTOܕ type SuitDto = Heart = 1 | Spade
= 2 | Diamond = 3 | Club = 4 type RankDto = Ace = 1 | Two = 2 | Queen = 12 | King = 13 type CardDto = { Suit : SuitDto Rank : RankDto_attachment }
બܕ
type Example = | A | B of int |
C of string list | D of Name type ExampleDto = { Tag : string // "A", "B", "C", "D" ͷ͍ͣΕ͔1ͭ // έʔεAσʔλແ͠ BData : Nullable<int> // έʔεBͷσʔλ CData : string[] // έʔεCͷσʔλ DData : NameDto // έʔεDͷσʔλ }
ӬଓԽ
ʹ͍Ζ͏
Ͳ͏ͬͯʁ
// υϝΠϯϩδοΫͱI/O͕ࠞࡏ͢ΔϫʔΫϑϩʔ let payInvoice invoiceId payment = // DB͔ΒಡΈࠐΉ let
invoice = loadInvoiceFromDatabase(invoiceId) // ࢧ͍Λద༻͢Δ invoice.ApplyPayment(payment) // ҟͳΔ݁ՌΛॲཧ͢Δ if invoice.IsFullyPaid then markAsFullyPaidInDb(invoiceId) postInvoicePaidEvent(invoiceId) else markAsPartiallyPaidInDb(invoiceId)
// ڥք͚ͮΒΕͨίϯςΩετͷʹ͋ΔίϚϯυϋϯυϥʔ let payInvoice payInvoiceCommand = // DB͔ΒಡΈࠐΉ let invoiceId
= payInvoiceCommand.InvoiceId let unpaidInvoice = loadInvoiceFromDatabase invoiceId // I/O // ७ਮͳυϝΠϯͰͷݺͼग़͠ let payment = payInvoiceCommand.Payment // ७ਮ let paymentResult = applyPayment unpaidInvoice payment // ७ਮ // ݁ՌΛॲཧ match paymentResult with | FullyPaid -> markAsFullyPaidInDb invoiceId // I/O postInvoicePaidEvent invoiceId // I/O | PartiallyPaid updatedInvoice -> updateInvoiceInDb updatedInvoice // I/O
1,2ͱ͔Ҿ͖ͯΔ