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:
@@ -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
|
||||
|
Reference in New Issue
Block a user