Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View avegaraju's full-sized avatar
🤘
I may be slow to respond.

Ashish avegaraju

🤘
I may be slow to respond.
View GitHub Profile
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)=
member this.updateProductDimensionWorkflow(productId, (height,length,weight,width)) =
productDimensionWorkflow.getProduct
|> productDimensionWorkflow.updateProduct
|> productDimensionWorkflow.notifyWarehouseWhenDimensionsUpdate
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) ->
public class Order
{
public OrderId Order{get;}
public Option<String> DiscountCode {get;}
//Constructor and other properies removed for brevity
}
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;
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
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;
type CardType =
| Visa
| MC
type PaypalId =
| Id of int
type CardNumber =
| Number of int
@avegaraju
avegaraju / Order.cs
Last active September 22, 2018 21:39
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,
[Property(Arbitrary = new[]
{
typeof (Generator)
})]
public void DiscountIsApplied_UponCheckout(decimal discount,
decimal price)
{
var productRequest = new ProductRequest()
{
Discount = discount,