Why are there MapThread and MapIndexed but no analogous functions for Scan?
What is the recommended way to Scan over a pair of datasets (ScanThread), or over an ordered dataset (ScanIndexed)?
Edit
The reason I don't want to use Map is because it builds up an expression, which wastes memory and time.
I need to apply function(s) f, g with no output (only side effects) on lists of entries:
data1 = {a,b,c,d,e};
data2 = {s,t,u,v,w};
(*MapThread correctly calls f[a,s], f[b,t], but builds up an expression*)
MapThread[f, {data1, data2}]
(*MapIndexed calls g[a,{1}], g[b,{2}], but builds up an expression*)
MapIndexed[g, data1]
I only want to scan over these entries, without wasting resources and time.
Map*versions and just add;it will be close, those rules apply: 46238 – Kuba Jul 24 '17 at 16:08Scanbehavior is preferable toMap? – MarcoB Jul 24 '17 at 16:09Mapbuilds up an expression which wastes time and memory; I needScan(see edit). – QuantumDot Jul 24 '17 at 16:27Mapbuilds up an expression which wastes time and memory; I needScan(see edit) – QuantumDot Jul 24 '17 at 16:27ScanIndexedis on the road map, not sure when it will appear though. – Daniel Lichtblau Jul 24 '17 at 16:28ScanThreadandScanIndexed? – QuantumDot Jul 24 '17 at 16:31MapandMapThreaddo. What we need are examples giving executable code. Real data and actual functions for which scanning would be better than mapping. – m_goldberg Jul 24 '17 at 16:34Scanis preferable toMap; I just need to know from them what to do in those situations if I need the threaded and indexed versions of these functions. – QuantumDot Jul 24 '17 at 16:38Scanvs.Mapuse cases, but he is asking you as the author of the question to provide us with an actual code case where one can appreciate a significant difference between Scan and Map, rather than just the perception of waste, so we can evaluate different possible solutions in terms of time and memory consumption. If you don't provide that, you will only get answers from those that have had the problem, and solved it, which may rather significantly reduce your chances. – MarcoB Jul 24 '17 at 18:18GeneralUtilities`ScanIndexed, but it is just a high-level wrapper that delegates toDo,Scanor sometimes evenMapIndexed. – WReach Jul 24 '17 at 19:17Module[{i = 0}, Scan[f[#, {++i}] &, data1]]– jkuczm Jul 24 '17 at 19:28ScanThreadthe followingScan[f@@#&, Transpose[{data1,data2}]]; what do you think?) – QuantumDot Jul 24 '17 at 20:03Transpose[{data1,data2}]creates new list of pairs, so most likelyMapThread[f, {data1, data2}];orMapThread[(f@##; 0) &, {data1, data2}];will use same or less memory while being faster. – jkuczm Jul 24 '17 at 20:20