I have found myself recently typing over and over again similar code, namely something that looks like {f[#],g[#]}&@list
. Is there a 'better' way to achieve the same result?
I have come up with just this alternative Through[{f,g}[list]]
.
Can you think of a better way to do something like {First[#],Rest[#]}&@list
or {Mean[#],StandardDeviation[#]}&@list
?
Also, is the way that Through
is used, appropriate?
update:
I would like to refrain from using Map
, or Apply
if that is possible. I just want a 'native' robust way to manipulate lists or parts of lists in 'one pass' so to speak.
update2: I am searching for a better, robust way to apply a series of functions on a list, quickly, reliably and with as little as possible typing involved. I don't have a problem to settle for an answer in the negative, or explore more specialized solutions, see comment on TakeDrop[]
.
Through[]
a lot. $\endgroup$#@list & /@ {f, g}
$\endgroup$Through@{f, g}@list
. That is what I mostly use. $\endgroup$Map
andApply
are not native methods for manipulating lists. $\endgroup$Map
andApply
are not native methods. What I wrote is that I am looking for ways other than using them to achieve the desired result on the use cases I described. Just trying to improve my coding skills by finding new solutions to old problems. I'm sorry if I was not clear about it. $\endgroup$