Hi,
In my case i have a function/API in my code.
Where i query a triemap and getting subset of the triemap.
This given function is a working one and i want to change it. here i am comparing the parameter dishTypeId to v.dishTypeId, this works well
public query func getDishesByDishTypeId (dishTypeId : Types.DishTypeId) : async [(Types.DishId, Types.Dish)] {
let trieOfDishes = Trie.filter<Types.DishId, Types.Dish>(dishes, func (k, v) { v.dishTypeId == dishTypeId } );
let arrayOfDishes : [(Types.DishId, Types.Dish)] = Iter.toArray(Trie.iter(trieOfDishes));
return arrayOfDishes;
};
here “v” represents one dish from dishes triemap
dish is having the below candid definition
public type Dish = {
dishId : DishId;
images : [Image];
defaultImage : Image;
name : Text;
defaultName : Text;
ingredientIds : [IngredientId];
description : Text;
mealTypeIds : [MealTypeId];
cuisineId : CuisineId;
dishTypeId : DishTypeId;
alternativeNames : [AlternativeName];
draft : Bool;
};
but i have to check mealTypeId in the next function, so i have to somehow check whether the mealTypeIds inside dish (here “v”) contains the passed mealTypeId how to do this? any idea? i am stuck on this for past 1 week, i am not getting a clue from any of the examples and even from cancan project? any help would be appreciated. Thanks in advance
NB: i am expecting something similar to this but i can’t find any useful functions like contains from the docs
public query func getDishesByDishTypeId (mealTypeId : Types.MealTypeId) : async [(Types.DishId, Types.Dish)] {
let trieOfDishes = Trie.filter<Types.DishId, Types.Dish>(dishes, func (k, v) {
v.mealTypeIds.contains(mealTypeId) //how to do this in motoko?!
} );
let arrayOfDishes : [(Types.DishId, Types.Dish)] = Iter.toArray(Trie.iter(trieOfDishes));
return arrayOfDishes;
};