Make an Into Helper to Remove Boilerplate and Simplify our Transduce API

Paul Frend
InstructorPaul Frend

Share this video with your friends

Send Tweet

Our transduce function is powerful but requires a lot of boilerplate. It would be nice if we had a way to transduce into arrays and objects without having to specify the inner reducer behaviour, i.e. how to build up values, since a given collection type will almost always have the same inner reducer.

In this lesson we'll being doing just that with an into() helper function that will know if an array or object collection is passed in and handle each case accordingly.

Bijoy Thomas
Bijoy Thomas
~ 3 years ago

Hey Paul, right about 4:06 into the video (when you say "to recap..."), the order of the composition changes to compose(map(), filter()) when it should be compose(filter(), map()). The former ordering will return an empty object since it will fail the filter prediacte.

Briisk Sp. z o.o.
Briisk Sp. z o.o.
~ 3 years ago

Hey Paul, right about 4:06 into the video (when you say "to recap..."), the order of the composition changes to compose(map(), filter()) when it should be compose(filter(), map()). The former ordering will return an empty object since it will fail the filter predicate.

That's right, I noticed the same. And I also noticed that when used as a transformer the compose function works like the pipe and vice-versa. Composed functions get called normally from right to left but in this case it's from left to right, that took me a while to sink in :-D

Paul Frend
Paul Frendinstructor
~ 3 years ago

@Briisk @Bijoy Thanks for spotting the mistake guys. I recorded it the wrong way around first and then re-recorded the visuals that showed that bit, but must have missed the last few seconds. Sorry about that.

At least the code sample is correct :)