I've written a function, which I intended to Map over lists of some 8,000 element pairs.
I created the "toy" code below to illustrate my problem.
yld = 0.0742;
pVal = 10000;
pVal2 = 10000;
dataPairs = {{a, 0.0027}, {b, 0.0027}, {c, 0.0027}, {d, 0.002}, {e, 0}, {f, 0.0027}, {g, 0.002}};
f[dataPairs_] := Module[{date, prem, pValX, preQ},
prem = yld * dataPairs[[2]]*pVal2;
pValX = pVal2 + prem;
preQ = Which[
pVal >= pValX, True,
pVal < pValX, False];
{dataPairs[[1]], preQ}];
f[#] & /@ dataPairs
Which outputs:
{{a, False}, {b, False}, {c, False}, {d, False}, {e, True}, {f, False}, {g, False}}
I have 11,500 of these 8,000 element long lists. It gets be a lot of run time.
From each of these lists, I really only need the mapping to run until I get a the first paired output with True in it, e.g., {e, True}.
On average I expect to get a True, within the first 1250 applications of the function (f[]) to each of the 8,000 element long lists. If I can break the mapping when I first get True, it would vastly reduce the run time of the larger program.
Using NestWhile or FoldWhile, didn't seem to make sense because I don't need to build up iterative calculation on calculation.
I've considered SelectFirst, with the test for True as the criteria, but haven't had success.
Thoughts and suggestions appreciated.
TakeWhile[list, Not@*Last]? – Michael E2 Feb 27 '23 at 21:28