Created
April 30, 2021 16:51
-
-
Save mschauer/c94ef41987657163e595db91f4993e7a to your computer and use it in GitHub Desktop.
Map (running) pairs with f and reduce with r
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mappairreduce(r, f, itr, dec) | |
| ϕ = iterate(itr) | |
| if ϕ === nothing | |
| return dec | |
| end | |
| xlast, state = ϕ | |
| while true | |
| ϕ = iterate(itr, state) | |
| if ϕ === nothing | |
| return dec | |
| end | |
| x, state = ϕ | |
| dec = r(dec, f(xlast, x)) | |
| xlast = x | |
| end | |
| end | |
| mappairreduce(&, <, 1:10, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment