How can I pass a function with arguments in map?

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,


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)


Thanks! That works. Sorry for late response.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.