Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Viewed 284 times
8
$\begingroup$

If there is a one-variable function, we can f/@{a,b,c} to get {f[a],f[b],f[c]}

What to do with it if it comes to a binary function f[#1,#2]&, and a list {a,b,c}

and we want to "Map" it into a list funtion {f[#1,a],f[#1,b],f[#1,c]}&

I have found a strange way:

MapThread[f,{Table[#,3],{a,b,c}]&

though mathematica can't expand it, but it can actually work?! [doge]

if we add [x] behind it, we get the answer

MapThread[f,{Table[#,3],{a,b,c}]&[x]
>>> {f[x, a], f[x, b], f[x, c]}
$\endgroup$
2
  • 3
    $\begingroup$ Function@Evaluate@Map[Function[x, f[#, x]]]@{a, b, c}? $\endgroup$
    kglr
    –  kglr
    2022-04-11 12:12:40 +00:00
    Commented Apr 11, 2022 at 12:12
  • 3
    $\begingroup$ .. or Evaluate[f @@@ Thread[{#, {a, b, c}}]] & $\endgroup$
    kglr
    –  kglr
    2022-04-11 12:13:32 +00:00
    Commented Apr 11, 2022 at 12:13

1 Answer 1

10
$\begingroup$
Function[{x},f[y,x]] /@ {a,b,c} //
Function[y,#]&

Function[y, {f[y, a], f[y, b], f[y, c]}]

Also, you may want to check this: https://en.wikipedia.org/wiki/Currying

$\endgroup$

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.