This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UpdateProductDimensions | |
open Domain | |
open System | |
let find (productId:int, products: seq<Product>):Option<Product> = | |
products | |
|> Seq.tryPick<Product, Product>(fun x-> if x.ProductId = productId then Some(x) else None) | |
let update (productOption: Option<Product>, height, length, weight, width)= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
member this.updateProductDimensionWorkflow(productId, (height,length,weight,width)) = | |
productDimensionWorkflow.getProduct | |
|> productDimensionWorkflow.updateProduct | |
|> productDimensionWorkflow.notifyWarehouseWhenDimensionsUpdate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Order(selectedPaymentMethod: PaymentMethod, | |
discountCode: Option<string>) = | |
let paymentMethod pm = | |
match pm with | |
| x when x = CashOnDelivery -> | |
printfn "Cash on delivery" | |
| Paypal id-> | |
printf "paid by paypal %A" id | |
| Card (cardNumber , cardType) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
public OrderId Order{get;} | |
public Option<String> DiscountCode {get;} | |
//Constructor and other properies removed for brevity | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Result<Unit> ApplyDiscountWhenAvailable(Option<string> discountCode) | |
{ | |
return discountCode.Match(Some: ApplyDiscount, | |
None: () => Unit.Default); | |
} | |
private Result<Unit> ApplyDiscount(string discountCode) | |
{ | |
//mimic applying discount code (whatever that means) | |
return Unit.Default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Order(paymentMethod: PaymentMethod, discountCode: Option<string>)= | |
//Other members removed for brevity | |
member val PaymentMethod: PaymentMethod = paymentMethod with get | |
member val DiscountCode: Option<String> = discountCode with get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void PaymentMethod(object o) | |
{ | |
switch (o) | |
{ | |
case string s when s.Contains("CashOnDelivery"): | |
Console.WriteLine("cash on delivery"); | |
break; | |
case Paypal pId when pId.Id != null: | |
Console.WriteLine($"paypal {pId.Id}"); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CardType = | |
| Visa | |
| MC | |
type PaypalId = | |
| Id of int | |
type CardNumber = | |
| Number of int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Order | |
{ | |
public OrderId OrderId { get; } | |
public CustomerId CustomerId { get; } | |
public IReadOnlyCollection<OrderLine> OrderLines { get; } | |
public IPaymentMethod PaymentMethod {get;} | |
public DiscountCode DiscountCode {get;} | |
public Order(OrderId orderId, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Property(Arbitrary = new[] | |
{ | |
typeof (Generator) | |
})] | |
public void DiscountIsApplied_UponCheckout(decimal discount, | |
decimal price) | |
{ | |
var productRequest = new ProductRequest() | |
{ | |
Discount = discount, |