# Updating / adding a value for a table

Having a table given by, let's say

data = {a,b,c,d},{e,f,g,h}

how can I update data in a simple way

data = Something[data]

to display

data = {a,b,c,d, operation[a,b,c,d]},{e,f,g,h, operation[e,f,g,h]}

for a given function "operation"?

Specifically, I'm finding solutions for an expression function == 1 using a RandomSearch, but I'd like to display also the resulting value that is close to target in each search:

target = 1

solutionCandidates =
Table[NMinimize[{Abs[(function[var1, var2, var3] -
target)^2], var1min < var1 < var1max, var2min < var2 < var2max, var3min < var3 < var3max}, {var1, var2, var3},
Method -> {"RandomSearch", "RandomSeed" -> i,
"SearchPoints" -> 10}], {i, 10}];

solutions = Select[solutionCandidates, #[[1]] < 10^-10 &][[All, 2]];


data = {{a, b, c, d}, {e, f, g, h}};

{##, operation @ ##} & @@@ data

{{a, b, c, d, operation[a, b, c, d]},
{e, f, g, h, operation[e, f, g, h]}}


Try Map !

As a simple example

func = # . # &
Map[Join[#, {func[#]}] &, {{a, b, c, d}, {e, f, g,h}}, 1]
(*{{a, b, c, d, a^2 + b^2 + c^2 + d^2}, {e, f, g,h,e^2 + f^2 + g^2 + h^2}}*)

data = {{a, b, c, d}, {e, f, g, h}}
f[k_List] := {Sequence @@ k, f @@ k}


Map this function on each data item or as required.

f /@ data


{{a, b, c, d, f[a, b, c, d]}, {e, f, g, h, f[e, f, g, h]}}

lst = {{a, b, c, d}, {e, f, g, h}}
Append[#, operation[#]] & /@ lst


Using Query

data = {{a, b, c, d}, {e, f, g, h}};

Query[All, {Apply[Sequence], Apply[operation]}] @ data


gives

{{a, b, c, d, operation[a, b, c, d]},
{e, f, g, h, operation[e, f, g, h]}}

data = {{a, b, c, d}, {e, f, g, h}};


Using ComapApply (new in 14.0)

ComapApply[{Sequence, op}] /@ data


returns

{{a, b, c, d, op[a, b, c, d]},
{ e, f, g, h, op[e, f, g, h]}}


Using MapThread:

data = {{a, b, c, d}, {e, f, g, h}};

MapThread[Append, {#, operation @@@ #}] &@data

(*{{a, b, c, d, operation[a, b, c, d]}, {e, f, g, h, operation[e, f, g, h]}}*)


Also, using Flatten:

Flatten[{##, operation[##]}] & @@@ data

(*{{a, b, c, d, operation[a, b, c, d]}, {e, f, g, h, operation[e, f, g, h]}}*)