
Show HN: LazyCode – C++14 composable, lazily evaluated map, filter, fold - SaadAttieh
https://github.com/SaadAttieh/lazyCode
======
hobo_mark
And some user just opened an issue titled "Where are the tests?" and nothing
else. Sure that's a valid concern, but that's the kind of attitude that would
make me disable or lock GitHub issues in a project altogether (I have no
relationship at all with this specific project).

------
kazinator
Composable, lazily evaluated map, filter and fold in C90:

    
    
      This is the TXR Lisp interactive listener of TXR 204.
      Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet.
      1> (take 15 [keep-if* oddp (mapcar* [dup *] (range 0))])
      (1 9 25 49 81 121 169 225 289 361 441 529 625 729 841)
    

Lazy keep-if:
[http://www.kylheku.com/cgit/txr/tree/lib.c?id=c310771b221125...](http://www.kylheku.com/cgit/txr/tree/lib.c?id=c310771b221125d3ff419662ce74f6b505fe638f#n1874)

Lazy mapcar:
[http://www.kylheku.com/cgit/txr/tree/eval.c?id=c310771b22112...](http://www.kylheku.com/cgit/txr/tree/eval.c?id=c310771b221125d3ff419662ce74f6b505fe638f#n5170)

Lazy range:
[http://www.kylheku.com/cgit/txr/tree/eval.c?id=c310771b22112...](http://www.kylheku.com/cgit/txr/tree/eval.c?id=c310771b221125d3ff419662ce74f6b505fe638f#n5397)

P.S. _dup_ generates a one-argument function which duplicates its argument
into two places and calls another function. [dup *] gives us a squaring
function, thus.

------
Waterluvian
Is the pipe idiomatic c++ or is this an operator overload that requires
readers to go learn a new piece of syntax?

~~~
shawxe
The pipe is an operator overload. That said, while I wouldn't exactly call it
idiomatic, it's not entirely unheard of in third party libraries. RxCpp
([https://github.com/ReactiveX/RxCpp](https://github.com/ReactiveX/RxCpp)),
the C++ ReactiveX library, makes use of a similarly overloaded pipe operator,
for example.

Personally, I think I'd be more apt to use the "functional" style.

------
cheez
Just read through the code, really easy to read. Nice post, thank you.

