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
20250610 関数型DDD 11
Search
saka
December 24, 2025
9
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
20250610 関数型DDD 11
saka
December 24, 2025
More Decks by saka
See All by saka
20250304 関数型DDD 6
sakatttttta
0
25
20241219 Github Actionsの面倒いところ
sakatttttta
0
18
20250109 関数型
sakatttttta
0
11
20250116 関数型DDD 2
sakatttttta
0
11
20250123 関数型DDD 3
sakatttttta
0
11
20250206 関数型DDD 4
sakatttttta
0
12
20250213 関数型DDD 4
sakatttttta
0
12
20250220 Hono カスタムfetch
sakatttttta
0
10
20250225 関数型DDD 5
sakatttttta
0
9
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
We Are The Robots
honzajavorek
0
400
Discover your Explorer Soul
emna__ayadi
2
1.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Site-Speed That Sticks
csswizardry
13
1.6k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Optimizing for Happiness
mojombo
378
71k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Transcript
DDD
લճ
ΤϥʔΛྨ
υϝΠϯΤϥʔ υϝΠϯϞσϦϯάʹΈࠐ ΈɺܕγεςϜʹจॻԽ
ύχοΫ ྫ֎Λൃੜͤ͞ɺ࠷্ҐͰิ
ΠϯϑϥετϥΫ νϟΤϥʔ ΞʔΩςΫνϟʹΑΔ େମυϝΠϯΤϥʔʹؚΊΔ ํཱ͕ͭ ↓ ͲΜͳΤϥʔ͕ى͜Δ͔ߟ͑Δ
Resultܕ
None
Ξμϓλʔ
Լܨ͛Δ
ίʔυͷલʹ
ཁ • ೖྗ • 1τϥοΫͷؔ • 2τϥοΫͷ • ग़ྗ •
2τϥοΫ • ͜ΕΛϥοϓͯ͋͛͠Δ • ೖྗΛ2τϥοΫɺग़ྗ2τϥοΫͷ ؔʹม͑ͯ͋͛Δ
͍͍ͨؔ Result<a, e> લͷؔͷ݁Ռͱ͔ Successͷ߹ద༻ͯ͠ฦ͢ Errorͷ߹ͦͷ··errorΛฦ͢ let bind switchFn twoTrackInput
= match twoTrackInput with | Ok success -> switchFn success | Error failure -> Error failure
αϯϓϧ
TS
map
ҧ͍ OkͰแΜͰฦ͍ͯ͠Δ ͖ͬ͞ͷa->Result ͬͪ͜ a->b let map f aResult =
match aResult with | Ok success -> Ok (f success) | Error failure -> Error failure
ڞ௨ͷΤϥʔܕ
Τϥʔͣͬͱ ԼͷϨʔϧΛΔ
ڞ௨ͷΤϥʔܕʹ͢Δඞ ཁ͕͋Δ
͜Εͩͱerror͕ҧ͏ͷͰ߹Ͱ͖ͳ͍ type FunctionA = Apple -> Result<Bananas, AppleError> type FunctionB
= Bananas -> Result<Cherries, BananaError>
ڞ௨ͷΤϥʔܕΛ࡞ type FruitError = | AppleErrorCase of AppleError | BananaErrorCase
of BananaError
let mapError f aResult = match aResult with | Ok
success -> Ok success | Error failure -> Error (f failure)
let functionA : FunctionA = ... let functionAWithFruitError input =
input |> functionA |> Result.mapError (fun appleError -> AppleErrorCase appleError) ͜Ε࣍ͷΑ͏ʹ؆ུԽͰ͖·͢ɻ let functionAWithFruitError input = input |> functionA |> Result.mapError AppleErrorCase
߹Ͱ͖ΔΑ͏ʹͳͬͨ let functionAWithFruitError input = input |> functionA |> Result.mapError
AppleErrorCase // "FruitError"Λ༻͢ΔΑ͏ʹfunctionBΛม͢Δ let functionBWithFruitError input = input |> functionB |> Result.mapError BananaErrorCase // ৽͍ؔ͠ "bind" Ͱ߹Ͱ͖Δ let functionAB input = input |> functionAWithFruitError |> Result.bind functionBWithFruitError
͜ΕΛPlaceOrderͱ͔ʹ ͍ͬͯ͘
αϯϓϧఔʹ // PlaceOrderErrorΛฦ͢Α͏ʹมͨ͠ let validateOrderAdapted input = input |> validateOrder
// ݩͷؔ |> Result.mapError PlaceOrderError.Validation // PlaceOrderErrorΛฦ͢Α͏ʹมͨ͠ let priceOrderAdapted input = input |> priceOrder // ݩͷؔ |> Result.mapError PlaceOrderError.Pricing ͜Ε͕ऴΘΔͱɺ࠷ऴతʹ bind ΛͬͯɺͦΕΒΛ࿈ͤ͞ΒΕΔ let placeOrder unvalidatedOrder = unvalidatedOrder |> validateOrderAdapted // มޙͷؔ |> Result.bind priceOrderAdapted // มޙͷؔ
ྫ֎ॲཧ
Try-catch AdapterͰResultܕ let serviceExceptionAdapter2 serviceInfo serviceFn x y = try
Ok (serviceFn x y) with | :? TimeoutException as ex -> ... | :? AuthorizationException as ex -> ...
ߦ͖ࢭ·Γؔ
ϩάͱ͔ // string -> unit let logError msg = printfn
"ERROR %s" msg
લͷΛͦͷ·· ߦ͖ࢭ·Γͷؔ // ('a -> unit) -> ('a -> 'a)
let tee f x = f x x
mapͰResult
// ('a -> unit) -> (Result<'a, 'error> -> Result<'a, 'error>)
let adaptDeadEnd f = Result.map (tee f)