I&C SCI 33 Lecture 14: [Functional Programming]
Document Summary
Functional programming programming tasks: functional programming is a style of programming that uses the simplicity and power of functions to accomplish. In functional programming, we don"t change data structures but produce new ones that are variants of the old ones. Map/transform, filter, reduce/accumulate: three important higher-order functions used in functional programming (each operates on a function and an iterable, which means they operate on lists and tuples easily): It returns a map object which can be cast as a list. print(list(map((lambda x: x**2), range(0, 6)))) --> prints [0,1,4,9,16,25] It returns a filter object which can be cast as a list. print(list(filter((lambda x: x > 0), range( 5, 5)))) --> prints [1,2,3,4] Because it only returns the values in the range that are > 0. Reduce (aka accumulate): pattis definition: this function is different than the previous two: it takes a binary function (which takes two arguments)and some list/iterable of values and typically produces a single value: it reduces or.