1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-07-31 12:00:34 +02:00

Make myMap work on empty lists

Which is cleaner and the correct thing to do.
This commit is contained in:
Bruno
2013-07-01 17:18:15 +02:00
parent 2431545594
commit 5d946b13fa

View File

@@ -155,7 +155,7 @@ foo (x, y) = (x + 1, y + 2)
-- Pattern matching on arrays. Here `x` is the first element
-- in the array, and `xs` is the rest of the array. We can write
-- our own map function:
myMap func [x] = [func x]
myMap func [] = []
myMap func (x:xs) = func x:(myMap func xs)
-- Anonymous functions are created with a backslash followed by