Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Ashish avegaraju

I may be slow to respond.
View GitHub Profile
View referentiality.fs
member this.updateProductDimensionWorkflow(productId, (height,length,weight,width)) =
|> productDimensionWorkflow.updateProduct
|> productDimensionWorkflow.notifyWarehouseWhenDimensionsUpdate
avegaraju / UpdateProductDimensionsUseCase.fs
Last active Dec 25, 2018
Use case to update product dimensions with dependencies injected through the type constructor
View UpdateProductDimensionsUseCase.fs
type UpdateProductDimensions(dataStore: DataStore)=
//Other private methods removed for brevity
let updateDimensions(productId, height, length, weight, width)=
dataStore.getProduct productId
|> p-> p.updateDimensions(height, length, weight, width))
|> dataStore.updateProduct
member this.update (productId, (height,length,weight,width)) =
View OptionInspection.cs
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;
View LanguageExtCSharpOrder.cs
public class Order
public OrderId Order{get;}
public Option<String> DiscountCode {get;}
//Constructor and other properies removed for brevity
View FSharpOption.fs
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
View CSharp7PatternMatch.cs
public void PaymentMethod(object o)
switch (o)
case string s when s.Contains("CashOnDelivery"):
Console.WriteLine("cash on delivery");
case Paypal pId when pId.Id != null:
Console.WriteLine($"paypal {pId.Id}");
View PaymentMethodPatternMatching.fs
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) ->
View FSharpUnion.fs
type CardType =
| Visa
| MC
type PaypalId =
| Id of int
type CardNumber =
| Number of int
View Order.cs
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,
View OrderTests.cs
[Property(Arbitrary = new[]
typeof (Generator)
public void DiscountIsApplied_UponCheckout(decimal discount,
decimal price)
var productRequest = new ProductRequest()
Discount = discount,