I'm trying to use Table[] more to be more in the spirit of Mathematica. So for example, I might replace this piece of code:
MySimpleFn[a_] := (
Return[a^5];)
myList = {};
Do[fnOutput = MySimpleFn[i];
AppendTo[myList, {i, fnOutput}];, {i, 5}];
With the more efficient
MySimpleFn[a_] := (
Return[a^5];)
Table[{i, MySimpleFn[i]}, {i, 5}]
But now let's say instead of MySimpleFn[], it's a function that takes a significant amount of time to calculate, MyHugeMessyLongFn[], and instead of one return value, it returns a pair, {a,b}.
Now, I know how I'd avoid calling the function twice with a loop, just:
myList = {};
Do[
fnOutput = MyHugeMessyLongFn[i];
fnOutput1 = fnOutput[[1]];
fnOutput2 = fnOutput[[2]];
AppendTo[myList, {i, fnOutput1,fnOutput2}];, {i, 5}];
But how can I do this with Table[]? If I did
Table[{i, MyHugeMessyLongFn[i][[1]], MyHugeMessyLongFn[i][[2]]}, {i, 5}]
I assume it would call it twice, right? Is there a way to use table for more extended operations, essentially?