mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-05 22:37:42 +02:00
Merge pull request #74 from brunal/patch-1
Make myMap work on empty lists
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
|
-- Pattern matching on arrays. Here `x` is the first element
|
||||||
-- in the array, and `xs` is the rest of the array. We can write
|
-- in the array, and `xs` is the rest of the array. We can write
|
||||||
-- our own map function:
|
-- our own map function:
|
||||||
myMap func [x] = [func x]
|
myMap func [] = []
|
||||||
myMap func (x:xs) = func x:(myMap func xs)
|
myMap func (x:xs) = func x:(myMap func xs)
|
||||||
|
|
||||||
-- Anonymous functions are created with a backslash followed by
|
-- Anonymous functions are created with a backslash followed by
|
||||||
|
Reference in New Issue
Block a user