File tree 2 files changed +3
-6
lines changed
2 files changed +3
-6
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,13 @@ singleton a = [a]
92
92
93
93
-- | Get the first element in an array, or `Nothing` if the array is empty
94
94
head :: forall a . [a ] -> Maybe a
95
- head (x : _) = Just x
96
- head _ = Nothing
95
+ head xs = xs !! 0
97
96
98
97
-- | Get the last element in an array, or `Nothing` if the array is empty
99
98
-- |
100
99
-- | Running time: `O(n)` where `n` is the length of the array
101
100
last :: forall a . [a ] -> Maybe a
102
- last (x : [] ) = Just x
103
- last (_ : xs) = last xs
104
- last _ = Nothing
101
+ last xs = xs !! (length xs - 1 )
105
102
106
103
-- | Get all but the first element of an array, creating a new array, or `Nothing` if the array is empty
107
104
-- |
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import qualified Data.Array as A
11
11
12
12
-- | Get the first element of a non-empty array.
13
13
head :: forall a . [a ] -> a
14
- head (x : _) = x
14
+ head xs = unsafeIndex xs 0
15
15
16
16
-- | Get all but the first element of a non-empty array.
17
17
tail :: forall a . [a ] -> [a ]
You can’t perform that action at this time.
0 commit comments