Last active
December 25, 2018 08:09
Star
You must be signed in to star a gist
Use case to update product dimensions with dependencies injected through the type constructor
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 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