List compositions are created using the Array.reduce() method. Just like the map() method, reduce() iterates through a list, performing a transformation on each value. The difference is that an initial value is also passed, which the items are composed onto, creating a smaller, reduced list or even a single return value.
- Another thing we might want to do with a list of values…is to compose those values together.…Remember I said earlier, so I want to remind you,…we're not talking, when I say list composition,…I don't mean composing two lists together.…We have a method for that, it's called concat.…But that isn't as traditionally thought of…from a functional perspective.…So what we're talking about here…is composition of items within a list.…Either a full composition,…which is what most people mean by it,…or sometimes it's just a partial composition.…
That's also valid.…And that goes by the name in functional programming of,…typically it's called a reduce.…So what are some examples of a reduction that we might do,…a composition that we might do across a list?…Say I have a list of numbers,…remember I had a transform where I multiplied…all those numbers by two, what if now I wanted to say,…I want to take this list of numbers…and add all of them together.…I want the summation of all the items in my list.…You can express the summation of items in a list…
This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.
- Pure functions
- Manual composition
- Composition utility
- List operations
Skill Level Intermediate
1. Pure Functions
2. Composition and Immutability
3. Closure and Recursion
4. List Operations
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.