Skip to content

Instantly share code, notes, and snippets.

@avegaraju
Last active December 25, 2018 08:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save avegaraju/18a503c2351100ee5c3568efc8426f49 to your computer and use it in GitHub Desktop.
Use case to update product dimensions with dependencies injected through the type constructor
type UpdateProductDimensions(dataStore: DataStore)=
//Other private methods removed for brevity
let updateDimensions(productId, height, length, weight, width)=
dataStore.getProduct productId
|> Result.map(fun p-> p.updateDimensions(height, length, weight, width))
|> Result.map dataStore.updateProduct
member this.update (productId, (height,length,weight,width)) =
dataStore.productExists productId
|> Result.bind(function
| Some p -> updateDimensions(p, height, length, weight, width)
| None -> Error(new exn (sprintf "Product %i does not exist." productId)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment