diff options
Diffstat (limited to 'models/fertilizer-product.rkt')
| -rw-r--r-- | models/fertilizer-product.rkt | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/models/fertilizer-product.rkt b/models/fertilizer-product.rkt index e79a707..652b3c4 100644 --- a/models/fertilizer-product.rkt +++ b/models/fertilizer-product.rkt @@ -7,7 +7,9 @@ (rename-out [fertilizer-product-canonical-name fertilizer-product-name] [fertilizer-product-nutrient-values fertilizer-product-values] [fertilizer-product-brand-name fertilizer-brand-name]) - (contract-out [create-fertilizer-product! (-> fertilizer-product? fertilizer-product?)] + (contract-out [create-fertilizer-product! + (case-> (-> fertilizer-product? fertilizer-product?) + (-> string? string? nutrient-value-hash/c fertilizer-product?))] [get-fertilizer-products (-> (listof fertilizer-product?))] [get-fertilizer-product (->* () (#:id db-id? #:canonical-name string?) (or/c fertilizer-product? #f))] @@ -56,7 +58,14 @@ ;; CREATE -(define (create-fertilizer-product! fp) +(define create-fertilizer-product! + (case-lambda + [(fp) (create-fertilizer-product!/fp fp)] + [(canonical-name brand-name nutrient-values) + (create-fertilizer-product!/fp + (fertilizer-product #f canonical-name brand-name nutrient-values))])) + +(define (create-fertilizer-product!/fp fp) (define canonical-name (fertilizer-product-canonical-name fp)) (define brand-name (fertilizer-product-brand-name fp)) (define nutrient-values (fertilizer-product-nutrient-values fp)) @@ -196,10 +205,9 @@ (define nitrogen (get-nutrient #:name "Nitrogen")) (define phosphorus (get-nutrient #:name "Phosphorus")) - (create-fertilizer-product! (fertilizer-product #f - canonical-product-name - "MasterBlend" - (hash nitrogen 40 phosphorus 200))) + (create-fertilizer-product! canonical-product-name + "MasterBlend" + (hash nitrogen 40 phosphorus 200)) (check-equal? (length (get-fertilizer-products)) 1) @@ -238,9 +246,7 @@ (test-case "Custom write property formatting" (define nitrogen (get-nutrient #:name "Nitrogen")) - (define fp - (create-fertilizer-product! - (fertilizer-product #f "Test Fertilizer" "TestBrand" (hash nitrogen 50)))) + (define fp (create-fertilizer-product! "Test Fertilizer" "TestBrand" (hash nitrogen 50))) (define output (open-output-string)) (write fp output) |