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

20250213 関数型DDD 4

Avatar for saka saka
December 24, 2025
2

20250213 関数型DDD 4

Avatar for saka

saka

December 24, 2025

Transcript

  1. type PlaceOrderEvents = { AcknowledgmentSent : AcknowledgmentSent OrderPlaced : OrderPlaced

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

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

    -> Async<Result<ValidatedOrder, ValidationError list>> type ValidateOrder = UnvalidatedOrder -> ValidationResponse<ValidatedOrder>
  4. type PricedOrder = { OrderId : ... CustomerInfo : CustomerInfo

    ShippingAddress : Address BillingAddress : Address // ݕূࡁΈͷ஫จ໌ࡉߦͱ͸ҟͳΔ OrderLines : PricedOrderLine list AmountToBill : BillingAmount }
  5. type Order = | Unvalidated of UnvalidatedOrder | Validated of

    ValidatedOrder | Priced of PricedOrder // etc
  6. type ShoppingCart = | EmptyCart // σʔλແ͠ | ActiveCart of

    ActiveCartData | PaidCart of PaidCartData
  7. let addItem cart item = match cart with | EmptyCart

    -> // ࢦఆ͞ΕͨΞΠςϜͰɺ৽͍͠ΞΫςΟϒͳΧʔτΛ࡞੒ ActiveCart { UnpaidItems = [item] } | ActiveCart { UnpaidItems = existingItems } -> // ࢦఆ͞ΕͨΞΠςϜͱ௥ՃࡁΈͷΞΠςϜͰɺ৽͍͠ΞΫςΟϒͳΧʔτΛ࡞੒ ActiveCart { UnpaidItems = item :: existingItems } | PaidCart _ -> // ແࢹ cart