@@ -14,7 +14,7 @@ reads, updates, and appends.
1414@docs get, getOrElse, getOrFail, set
1515
1616# Taking Arrays Apart
17−@docs toList, toIndexedList, slice
17+@docs slice, toList, toIndexedList
1818
1919# Mapping and Folding
2020@docs map, indexedMap, foldl, foldr
@@ -163,13 +163,21 @@ If the index is out of range, the array is unaltered.
163163set : Int -> a -> Array a -> Array a
164164set = Native.Array.set
165165
166−{-| Slice an array given a range. The selection is inclusive, so the last
167−element in the selection will also be in the new array. This may change in the
168−future. You can select from the end by giving a negative Int.
166+{-| Get a sub-section of an array: `(slice start end array)`. The `start` is a
167+zero-based index where we will start our slice. The `end` is a zero-based index
168+that indicates the end of the slice. The slice extracts up to but not including
169+`end`.
169170
170− slice 1 2 (fromList [0,1,2,3,4]) == fromList [1,2]
171− slice 1 -2 (fromList [0,1,2,3,4]) == fromList [1,2,3]
172− slice -3 -2 (fromList [0,1,2,3,4]) == fromList [2,3]
171+ slice 0 3 (fromList [0,1,2,3,4]) == fromList [0,1,2]
172+ slice 1 4 (fromList [0,1,2,3,4]) == fromList [1,2,3]
173+
174+Both the `start` and `end` indexes can be negative, indicating an offset from
175+the end of the array.
176+
177+ slice 1 -1 (fromList [0,1,2,3,4]) == fromList [1,2,3]
178+ slice -2 5 (fromList [0,1,2,3,4]) == fromList [3,4]
179+
180+This makes it pretty easy to `pop` the last element off of an array: `slice 0 -1 array`
173181-}
174182slice : Int -> Int -> Array a -> Array a
175183slice = Native.Array.slice