4 ms·
PR's are welcome! I wrote the Clojure examples 6 years ago as a beginner whilst I was learning Clojure but I thought its built in functions were already well s
by mythz 7y ago
PR's are welcome!
I wrote the Clojure examples 6 years ago as a beginner whilst I was learning Clojure but I thought its built in functions were already well suited for LINQ examples.
Do you have an example where transducers would help with verbosity or readability?
- fiddlerwoaroof 7y agoI need to think about it, but they are more generic because they don’t make assumptions about the input sequence type and/or the resulting type. They are also more efficient because they don’t create any intermediate sequences.
- jeswin 7y agoI haven't dealt with LINQ lately, but IIRC there was no way to do early termination on a sequence. // Not ideal list.Select(x => ExpensiveFunc(x)).Take(5); Transducers can be terminated early - https://dev.to/greencoder/build-your-own-transducer-and-impress-your-cat---part-4-2bp8 https://dev.to/greencoder/build-your-own-transducer-and-impr...
- kevingadd 7y agoIEnumerable implicitly offers early termination. LINQ expressions are always implicit by default, so .Select(...).Take(n) will stop after taking N items. It's just like a foreach loop (same interface/API). For the same reason, if you 'foreach' over the result of a linq query multiple times, it will evaluate the whole sequence again, which often isn't what you want - so people tend to call .ToArray() or .ToList() at the end to fully evaluate it once.
- jeswin 7y ago> IEnumerable implicitly offers early termination. LINQ expressions are always implicit by default, so .Select(...).Take(n) will stop after taking N items. My bad, indeed it does! (Embarassing, my job used to be working on LINQ-based ORM libs. Though more than a decade back.)
- fulafel 7y agoClojure's normal transducerless lazy sequences are fine for early-terminating sequences.. mostly. They're fine as long as you are ok with realizing up to 31 extra items. http://clojure-doc.org/articles/language/laziness.html#lazy-sequences-chunking http://clojure-doc.org/articles/language/laziness.html#lazy-...