foldr and foldl Flashcards
Explain the map function
loop over list element-by-element, append new element to new list
Explain the foldl function
loop over list element-by-element, update accumulator using current accumulator and element
Explain the foldr function
foldr : loop over reverse list element-by-element, update accumulator using current accumulator and element
Give the map function definition
map :: (a -> b) -> [a] -> [b]
Give the foldl function definition
foldl :: (b -> a -> b) -> b -> [a] -> b
Give the foldr function definition
foldr :: (a -> b -> b) -> b -> [a] -> b
What is the difference between foldl and foldr
foldl evaluates from left to right (left-associative)
foldr evaluates from right to left (right-associative)