Hi All,
I have a map condition like below,
lines.position(|line| does_line_contain(line, "keyword"));
This works. Then I tried below and it fails,
lines.position(does_line_contain("keyword"));
Is it possible to do like this?
Hi All,
I have a map condition like below,
lines.position(|line| does_line_contain(line, "keyword"));
This works. Then I tried below and it fails,
lines.position(does_line_contain("keyword"));
Is it possible to do like this?
No, Rust doesn't support implicit partial application.
You could make a function that returns a closure, for example (essentially doing “manual” partial application):
fn does_line_contain(needle: &str) -> impl Fn(&str) -> bool + '_ {
move |haystack| haystack.contains(needle)
}
lines.position(does_line_contain("keyword"));
Thanks! That works. Sorry for late response.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.