add search for recipes by list of ingredients
This commit is contained in:
parent
14af854887
commit
ba43937232
31
parse.scm
31
parse.scm
|
@ -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))))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user