I need to exit foldl. Here is a dummy example of how to break from the fold when I am counting the sum of the values ββin a list and encountering a value too large (i.e. 10)
L = [1,2,3,4,10,5,6,7], Res = try lists:foldl( fun(I, Value) -> if (I < 10) -> Value + I; true -> throw({too_big_value, Value}) end end, 0, L) catch throw:{too_big_value, Value} -> Value end, Res.
I know this example is artificial, but is there any good way to break a crease (I know that creases always look through the whole structure)?
Please note that I need to get the correct data, even if I break. In this case, I should get the data from the previous iteration (as it was in my example).
source share