I have:
let x: Option<A>
let f: fn A -> Option<B>
I'm looking at Option in std::option - Rust andnot seeing a function that generates a (x, f) -> Option<B>
. Is there builtin function for this? (I expect "yes", but can't find the function.)
I have:
let x: Option<A>
let f: fn A -> Option<B>
I'm looking at Option in std::option - Rust andnot seeing a function that generates a (x, f) -> Option<B>
. Is there builtin function for this? (I expect "yes", but can't find the function.)
If I'm understanding this correctly, you want a Option
function that takes a value, and a function that returns a Option
using that value?
This is the exact same as just calling the function in the first place.
Unless you meant you wanted a function like so:
fn map<T, U>(a: Option<T>, f: impl Fn(Option<T>) -> Option<U>);
f is A -> Option<A>
, not Option<A> -> Option<B>
@sfackler 's and_then
is the function I was looking for.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.