File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,20 @@ Running time: `O(n)` where `n` is the length of the array
170170uncons :: forall a. Array a -> Maybe { head :: a, tail :: Array a }
171171```
172172
173- Break an array into its first element, and the remaining elements
173+ Break an array into its first element and remaining elements.
174+
175+ Using ` uncons ` provides a way of writing code that would use cons patterns
176+ in Haskell or pre-PureScript 0.7:
177+ ``` purescript
178+ f (x : xs) = something
179+ f [] = somethingElse
180+ ```
181+ Becomes:
182+ ``` purescript
183+ f arr = case uncons arr of
184+ Just { head: x, tail: xs } -> something
185+ Nothing -> somethingElse
186+ ```
174187
175188#### ` index `
176189
Original file line number Diff line number Diff line change @@ -210,7 +210,20 @@ init :: forall a. Array a -> Maybe (Array a)
210210init xs | null xs = Nothing
211211 | otherwise = Just (slice zero (length xs - one) xs)
212212
213- -- | Break an array into its first element, and the remaining elements
213+ -- | Break an array into its first element and remaining elements.
214+ -- |
215+ -- | Using `uncons` provides a way of writing code that would use cons patterns
216+ -- | in Haskell or pre-PureScript 0.7:
217+ -- | ``` purescript
218+ -- | f (x : xs) = something
219+ -- | f [] = somethingElse
220+ -- | ```
221+ -- | Becomes:
222+ -- | ``` purescript
223+ -- | f arr = case uncons arr of
224+ -- | Just { head: x, tail: xs } -> something
225+ -- | Nothing -> somethingElse
226+ -- | ```
214227uncons :: forall a . Array a -> Maybe { head :: a , tail :: Array a }
215228uncons = uncons' (const Nothing ) \x xs -> Just { head: x, tail: xs }
216229
You can’t perform that action at this time.
0 commit comments