title: Return multiple values from a mapped function
body: <p>Let's say I have a function named trig, which returns two outputs:</p>
  
  <pre><code>function trig(x)
      return(sin(x), cos(x))
  end
  </code></pre>
  
  <p>If I want to evaluate trig over many values, I can use the map function:</p>
  
  <pre><code>julia&gt; out = map(trig, (0:(pi/12):(pi/2)))
  </code></pre>
  
  <p>out is a 7 element array and in each element, there is a tuple containing two elements:</p>
  
  <pre><code>julia&gt; out
  7-element Array{Tuple{Float64,Float64},1}:
  (0.0,1.0)
  (0.258819,0.965926)
  (0.5,0.866025)
  (0.707107,0.707107)
  (0.866025,0.5)
  (0.965926,0.258819)
  (1.0,6.12323e-17)
  </code></pre>
  
  <p>My question is: What is the best way to disentangle my sines and cosines so that I have two arrays with 7 elements each? Is it possible to broadcast trig without creating the superfluous array of tuples and instead directly create the two arrays that I am actually interested in?</p>
  
  <p>For the time being, I am invoking map again in order to extract values from out in order to populate the arrays I want, but I don't think it is the best way to do this:</p>
  
  <pre><code>sines = map(x-&gt;x[1], out)
  cosines = map(x-&gt;x[2], out)
  </code></pre>
  
  <p>For the purpose of this question, assume trig is a computationally expensive function. So, please do not give me an answer that requires trig to be evaluated more than once.</p>