How does reduce work here? Is it like a function that gets called on each element, but also with the result of the previous elements? How does it keep the context/state required to combine every element in an array into a single output?
Andrew Brown You guessed it. A reduction is a function applied successively to each element with an additional argument, the accumulated value. This value is carried from its initial state (which you can provide) and must be passed back as the function result so it can be passed to the next calculation.
This is most powerful operation because with it you can create the other two operations or you can use it to calculate a length, a sum or an average etc. You can also use it to compose higher level functions (functions built out of other functions).
Thanks for the explanation. I’m familiar a bit with it in Ruby under the name “injections”, but wanted to make sure it mapped (heh) to generally the same concept!
Yes it’s pretty standard. It’s also known as a fold operation. Usually these operations come in pairs so you can process from left to right or right to left.
reduce usually gets an initial value as the reduce function combines two values, the current item of the list and the result of the previous reduce.
In lack of an initial element the neutral element wrt the reduce function and the set of elements can be used (0 with integer addition, 1 with multiplication etc).
What is the initial or neutral element in this case? Maybe air?
Shit is a Maybe monad with a value of Exists or None. I think Shit is also a monoid with an identity of None. Shit can be appended to in a reduction operation but appending anything other than None to it produces Exists.
Does isVegetarian() check isFriedInBeefTallow()? I’ma open a ticket if not.
LikeLike
in 2002 I had the following python filter expression cartooning the reflex patriotism of Americans:
filter(lambda W : W not in ‘ILLITERATE’,’BULLSHIT’)
LikeLike
John Hardy Turnbull delenda est did you create that? Nice work!
LikeLike
Bob Haugen no not mine. from out there in the aether
LikeLike
Actually, you can map all cook as shit.
LikeLike
How does reduce work here? Is it like a function that gets called on each element, but also with the result of the previous elements? How does it keep the context/state required to combine every element in an array into a single output?
LikeLike
Andrew Brown You guessed it. A reduction is a function applied successively to each element with an additional argument, the accumulated value. This value is carried from its initial state (which you can provide) and must be passed back as the function result so it can be passed to the next calculation.
This is most powerful operation because with it you can create the other two operations or you can use it to calculate a length, a sum or an average etc. You can also use it to compose higher level functions (functions built out of other functions).
LikeLike
Thanks for the explanation. I’m familiar a bit with it in Ruby under the name “injections”, but wanted to make sure it mapped (heh) to generally the same concept!
LikeLike
Yes it’s pretty standard. It’s also known as a fold operation. Usually these operations come in pairs so you can process from left to right or right to left.
LikeLike
reduce usually gets an initial value as the reduce function combines two values, the current item of the list and the result of the previous reduce.
In lack of an initial element the neutral element wrt the reduce function and the set of elements can be used (0 with integer addition, 1 with multiplication etc).
What is the initial or neutral element in this case? Maybe air?
LikeLike
Shit is a Maybe monad with a value of Exists or None. I think Shit is also a monoid with an identity of None. Shit can be appended to in a reduction operation but appending anything other than None to it produces Exists.
LikeLike
Peter da Silva depends on how isVegeterian(food) is written. If you don’t like the definition, write yourself a new one.
LikeLike
Brilliant. Where was this back when I needed to actually learn this.
LikeLike
https://plus.google.com/photos/…
LikeLike