Last active
August 29, 2015 14:03
-
-
Save Finomnis/ad0a8480fae4565ffaae to your computer and use it in GitHub Desktop.
Transform Reduce Initial Idea
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
This is how our current reduce algorithm works. | |
A A A A A A A A | |
split: | |
A A A A A A A A | |
accumulate: | |
A A A A | |
initial B->+->+->+->+->B | |
which takes all A's of one partition and accumulates it with f: B x A -> B | |
In the current case, type B == type A, so we take the first A as our initial B. | |
gather: | |
takes all result B's and combines them with g: B x B -> B to generate one finale result. | |
Right now, f and g are the same function, as type B == type A. | |
I propose we make it capable of handling input types different from output types. | |
But therefore we can't just let the user supply f and g, because that is unintuitive and leaves us with a missing initial B. | |
The setup i propose: | |
the reduce function reduce: B x B -> B | |
and the convert function conv: A -> B. | |
we calculate our initial B of every partition from the first element in every partition: | |
initB = conv(first_a). | |
our accumulate function is then: | |
f(B b, A a) | |
{ | |
return reduce(b, conv(a)); | |
} | |
and our gather function g is simply reduce. | |
if no conv function is supplied, we default to | |
conv(A a) | |
{ | |
return (B)a; | |
} | |
which, in the case of A == B is identical to our current implementation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment