You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a todo app and I use predicates-rs to filter tasks before displaying them to the user. My Task struct contains a id: TaskId field and I want to use predicate::in_hash to filter out tasks that have an id that is within a certain list.
I currently have code that looks roughly like this:
// base predicate that lets everything throughlet predicate = predicate::always().boxed();// BoxPredicate<Task>if filter_unactionable {let tasks_with_uncompleted_dependencies:Vec<TaskId> = task_database.iter_tasks().filter(|| ...).map(|t| t.id).collect();let has_uncompleted_dependencies = predicate::in_hash(tasks_with_uncompleted_dependencies);// HashableInPredicate<TaskId>
predicate = predicate.and(has_uncompleted_dependencies.not()).boxed();// error, differing types!}// other filters here// `predicate` is returned and later used to filter which tasks to display
This code does not work because my in_hash predicate expects a value of type TaskId while my main predicate expects Task.
To solve this, I'd like a way to "map" values before a predicate evaluates them. This could look like this (API is just a suggestion):
let predicate = predicate::always().boxed();// BoxPredicate<Task>if filter_unactionable {let tasks_with_uncompleted_dependencies:Vec<TaskId> = task_database.iter_tasks().filter(|| ...).map(|t| t.id).collect();let has_uncompleted_dependencies = predicate::in_hash(tasks_with_uncompleted_dependencies);// HashableInPredicate<TaskId>// map from Predicate<Task> to PredicateTaskIdlet has_uncompleted_dependencies_mapped = has_uncompleted_dependencies.map(|task:&Task| task.task_id);
predicate = predicate.and(has_uncompleted_dependencies_mapped.not()).boxed();}
The text was updated successfully, but these errors were encountered:
I am working on a todo app and I use predicates-rs to filter tasks before displaying them to the user. My
Task
struct contains aid: TaskId
field and I want to usepredicate::in_hash
to filter out tasks that have an id that is within a certain list.I currently have code that looks roughly like this:
This code does not work because my
in_hash
predicate expects a value of typeTaskId
while my main predicate expectsTask
.To solve this, I'd like a way to "map" values before a predicate evaluates them. This could look like this (API is just a suggestion):
The text was updated successfully, but these errors were encountered: