add search for recipes by list of ingredients

This commit is contained in:
Christoffer Müller Madsen 2017-04-05 12:19:03 +02:00
parent 14af854887
commit ba43937232

View File

@ -42,6 +42,33 @@
search-name)])))) search-name)]))))
(define contains-ingredient? (define contains-ingredient?
(lambda (recipe ingredient) (lambda (recipe search-ingredient)
(let ((ingredients (ingredients recipe))) (let ((ingredients (ingredients recipe)))
(ingredient-by-name ingredients ingredient)))) (ingredient-by-name ingredients search-ingredient))))
(define contains-ingredients?
(lambda (recipe search-ingredients)
(let ((ingredients (ingredients recipe)))
(cond [(null? search-ingredients) #t]
[(ingredient-by-name ingredients
(car search-ingredients))
(contains-ingredients? recipe
(cdr search-ingredients))]
[else #f])
)))
(define recipes-by-ingredients
(lambda (recipes search-ingredients list)
(if (null? recipes)
list
(let* ((recipe (car recipes))
(ingredients (ingredients recipe))
(contains? (contains-ingredients? recipe
search-ingredients)))
(if contains?
(recipes-by-ingredients (cdr recipes)
search-ingredients
(cons recipe list))
(recipes-by-ingredients (cdr recipes)
search-ingredients
list))))))