Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20250206 関数型DDD 4

Avatar for saka saka
December 24, 2025
1

20250206 関数型DDD 4

Avatar for saka

saka

December 24, 2025

Transcript

  1. work f low "Place Order" = input: UnvalidatedOrder output (on

    success): OrderAcknowledgmentSent AND OrderPlaced (to send to shipping) AND BillableOrderPlaced (to send to billing) output (on error): InvalidOrder
  2. // ܕΛఆٛ type CustomerId = CustomerId of int type OrderId

    = OrderId of int // ஋Λఆٛ let customerId = CustomerId 42 let orderId = OrderId 42 // CustomerIdΛ࢖͏ؔ਺Λఆٛ let processCustomerId (id: CustomerId) = ... // OrderIdΛ౉͢ͱ -- ίϯύΠϥʔΤϥʔʂ processCustomerId orderId
  3. type PlaceOrderEvents = { AcknowledgmentSent : AcknowledgmentSent OrderPlaced : OrderPlaced

    BillableOrderPlaced : BillableOrderPlaced } type PlaceOrder = UnvalidatedOrder -> PlaceOrderEvents
  4. type CategorizedMail = | Quote of QuoteForm | Order of

    OrderForm // etc type CategorizeInboundMail = EnvelopeContents -> CategorizedMail
  5. type ValidationResponse<'a> = Async<Result<'a, ValidationError list>> type ValidateOrder = UnvalidatedOrder

    -> Async<Result<ValidatedOrder, ValidationError list>> type ValidateOrder = UnvalidatedOrder -> ValidationResponse<ValidatedOrder>