on master help sign in
Allow push
dcba223Christian Widera
libraries/Array.elm+4−7
@@ -11,7 +11,7 @@ first into a list, operating on it, and then turning it back into an array.
11@docs empty, length, get, safeGet, getWithDefault
11@docs empty, length, get, safeGet, getWithDefault
12
12
13# Putting Arrays Together
13# Putting Arrays Together
14−@docs fill, fromList, concat, set, updates
14+@docs fill, fromList, concat, set, updates, push
15
15
16# Taking Arrays Apart
16# Taking Arrays Apart
17@docs elements, indices, assocs, slice
17@docs elements, indices, assocs, slice
@@ -21,6 +21,7 @@ first into a list, operating on it, and then turning it back into an array.
21-}
21-}
22
22
23import Native.Array
23import Native.Array
24+import Basic
24import List
25import List
25
26
26data Array a = Array
27data Array a = Array
@@ -109,13 +110,9 @@ zipWith f a b =
109empty : Array a
110empty : Array a
110empty = Native.Array.empty
111empty = Native.Array.empty
111
112
112−{- Push an item to the end of an array.
113+{-| Push an item to the end of an array. -}
113−This is implemented in Native, but one should be forced to accumulate a list of
114−new elements, turning it into an array and then concatting it. So it will remain
115−commented out for the moment.
116push : a -> Array a -> Array a
114push : a -> Array a -> Array a
117push = Native.Array.push
115push = Native.Array.push
118−-}
119
116
120{-| Return the value at the index. Breaks, if index is out of range. If the
117{-| Return the value at the index. Breaks, if index is out of range. If the
121array length is unkown, use safeGet oder getWithDefault.
118array length is unkown, use safeGet oder getWithDefault.
@@ -158,7 +155,7 @@ set = Native.Array.set
158 updates [(1,7),(2,8)] (fill 3 1) == fromList [1,7,8]
155 updates [(1,7),(2,8)] (fill 3 1) == fromList [1,7,8]
159-}
156-}
160updates : [(Int, a)] -> Array a -> Array a
157updates : [(Int, a)] -> Array a -> Array a
161−updates assocs array = List.foldl (uncurry Native.Array.set) array assocs
158+updates assocs array = List.foldl (Basic.uncurry Native.Array.set) array assocs
162
159
163{-| Slice an array given a range. The selection is inclusive, so the last
160{-| Slice an array given a range. The selection is inclusive, so the last
164element in the selection will also be in the new array. This may change in the
161element in the selection will also be in the new array. This may change in the