I have an association
<| a->f, b->g |>
where f
and g
are pure functions. Is there a nice way to apply arguments to both f
and g
? E.g.
<| a->f, b->g |>[x] --> <| a->f[x], b->g[x] |>
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI have an association
<| a->f, b->g |>
where f
and g
are pure functions. Is there a nice way to apply arguments to both f
and g
? E.g.
<| a->f, b->g |>[x] --> <| a->f[x], b->g[x] |>
As Kuba provided in a comment we can Map
a Function
that applies its argument to a specific expression, e.g. x
:
#[x] & /@ <|a -> f, b -> g|>
<|a -> f[x], b -> g[x]|>
Through[<|a -> f, b -> g|>[x]]
? No, it does not; the body evaluates to Missing["KeyAbsent", x]
. Through[Unevaluated[<|a -> f, b -> g|>[x]]]
gives Association[(a -> f)[x], (b -> g)[x]]
but I don't find that helpful. With[{asc = <|a -> f, b -> g|>}, Through[Unevaluated[asc[x]]]]
just kicks back Through[Unevaluated[<|a -> f, b -> g|>[x]]]
.
$\endgroup$
Sep 26, 2017 at 8:37