Category: reducer

Understanding the Almighty Reducer

I was reently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this: const nums = [1, 2, 3] let value = 0for (let i = 0; i < nums.length; i++) { value += nums[i] } …to this: const nums = [1, 2, 3] const value = nums.reduce((ac, next) => ac + next, 0) Th...

Transducers in PHP Made Easy

Have you heard of functional programming, high order functions, etc. before? Probably, right? However, when you hear “transducers”, do you know what those are?The Definition of Transducers We can’t define transducers without talking about reducers first. Quoting Rich Hickey:A reducing function is just the kin...