3 ms·
Also reduce is a weird name.
by mamcx 17d ago
Also reduce is a weird name.
- ingonealan3 17d agoWhy? It does, after all, reduce a collection to a single value.
- karmakurtisaani 17d agoI suppose it's just so ... reductive, you know?
- deleted 17d ago[deleted]
- ketzu 17d agoThe resulting value can be anything you want. You can turn a list into a tree, or another list. Bad example: reduce(lambda x,y: x+x.extend([y+2,y*2,y**2]), [1,2,3,4], []) Reduces the list to another list three times as long. It's a reduction in the sense of a transformation (also often seen in complexity theory), not in the "this makes this smaller" everyday usage that I think about first.
- EFreethought 17d agoIn the book "Simply Scheme", map is "every", filter is "keep", and reduce is "accumulate".
- nextaccountic 17d agoWhat about fold? In rust iterators there's both fold (you supply the initial value) and reduce (it uses the first element as the initial value, doesn't work on empty iterators) https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho... https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.reduce https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...