Skip to content

Instantly share code, notes, and snippets.

@mschauer
Created April 30, 2021 16:51
Show Gist options
  • Select an option

  • Save mschauer/c94ef41987657163e595db91f4993e7a to your computer and use it in GitHub Desktop.

Select an option

Save mschauer/c94ef41987657163e595db91f4993e7a to your computer and use it in GitHub Desktop.
Map (running) pairs with f and reduce with r
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