this, one of the problem with introducing lazy list
the iterator and generator faaks
these r disease in prog lang
that became pop since about 2010
since node js introduced async crap
Functional Style of Loop
the quest here, just become artificial and arbitrary
because, in fp, the fundamental loop form, is just a f call itself
then, we added map, reduce aka fold, to help this recursion as convenience
and in wolfram lang, they added mapthread, mapindexed, nest, nestwhile, etc. more convenience.
as to the specific question, of a generalized reduce with condition to stop, is just every, any, or more general, fixedpoint, nestwhile.
now, as for lazy eval, i don't think it's good
and to the degree, i think it's shit, should be ban'd.
and, while in practice, lazy eval is part of fp, but in my opinion, in theory, it is not part of fp.
lazy list, is fundamentally a loop. a state ridden, imperative shit.
lazy list, violates a fundamental principle of an aspect of function programing. namely, lazy list makes the lang view things as step by step instruction, not as mathematical declarations.
much things involving lazy list, make the function not a function. because it maintains a state.
similar situation, is the closure fuck.
Xah Lee — Yesterday at 12:28 PM
now, as to the oft cited advantage of infinite list, it is in practice, never needed.
nothing is infinite, even in math foundation, it's questionable.
now in particular of our computer hardware, nothing is infinite, and cannot be.
the lazy list as infinite list, is just a pretention.
u actually, always, deal with finite list.
possibly with incoming feed, as time pass by. eg stocks.
which, as u can see, is not a infinite list. but a time involved thing, time series. involving future.
Xah Lee — Yesterday at 12:49 PM
-------------
to recap, in fp, the fundamental form of loop, is recursive function
this came from theoretical comp sci and math. ie lambda calc, church numeral, recursive function aka computability
but in fp lang, some convenience is added.
map is the most common
it lets a f go thru a list, without needing to write f calling itself
second to map, is reduce.
it allows u to call f over a list, by nesting.
now, any and all is a generalized map. it add a condition to stop.
nest, nestwhile, fixedpoint, is generalized nest. the last two has a condition to stop.
let me rephrase this part.
nest, is convience, for f to nest. sans f calling itself.
fixedpoint, is a convience of nest. it has a condition to stop, when result no longer changes.
nestwhile, is more convience. it adds a general condition to stop.
reduce, is a mix of nest and map, for convenience.
mapthread, or just map in lisp and python, allows u to map a function of n args to n lists. kinda like parallel map.
mapindexed, is another convenience. it is like map, but index is also feed to the function, in many situations u wanna know the index.
another category. python range, for example, is also a convenience. it allows u to generate a list sans f calling itself.