Open holly-hacker opened 1 year ago
Would you be up for prototyping this within your project, creating extension traits to provide the syntax you want?
This will
I've already created my own predicate in my own project here: https://github.com/holly-hacker/td/commit/4f71543393cb662b01759128028bf3e76447f044#diff-ea57b46e48fccc26585162b2fa81cc63b45aa766280a22afa43c881a356b23cdR197
Usage looks roughly like this
let tasks_with_uncompleted_dependencies = self.database.get_all_tasks()
.filter(|t| ...)
.map(|t| t.id().clone())
.collect::<HashSet<_>>();
let has_uncompleted_dependencies = predicate::in_hash(tasks_with_uncompleted_dependencies);
let has_uncompleted_dependencies = MapPredicate::new(has_uncompleted_dependencies, |task: &Task| task.id());
predicate = predicate.and(has_uncompleted_dependencies.not()).boxed();
I opted to not write an extension trait for my current solution, but an ideal api would look something like this instead:
let has_uncompleted_dependencies = has_uncompleted_dependencies.map(|task: &Task| task.id()));
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):