on master help sign in
Change to better get function names
3ffe7d0Christian Widera
libraries/Array.elm+9−9
@@ -126,24 +126,24 @@ array length is unkown, use safeGet oder getWithDefault.
126get : Int -> Array a -> a
126get : Int -> Array a -> a
127get = Native.Array.get
127get = Native.Array.get
128
128
129−{-| Return Just the element at the index or Nothing.
129+{-| Return Just the element at the index or Nothing if the index is out of range.
130
130
131− safeGet 2 (A.fromList [3,2,1]) == Just 2
131+ getMaybe 2 (A.fromList [3,2,1]) == Just 2
132− safeGet 5 (A.fromList [3,2,1]) == Nothing
132+ getMaybe 5 (A.fromList [3,2,1]) == Nothing
133-}
133-}
134−safeGet : Int -> Array a -> Maybe a
134+getMaybe : Int -> Array a -> Maybe a
135−safeGet i array = if Native.Array.length array > i
135+getMaybe i array = if Native.Array.length array > i
136 then Just (Native.Array.get i array)
136 then Just (Native.Array.get i array)
137 else Nothing
137 else Nothing
138
138
139{-| Get the element at the index. If the index is out of range, the given default
139{-| Get the element at the index. If the index is out of range, the given default
140elementis returned.
140elementis returned.
141
141
142− getWithDefault 0 2 (A.fromList [3,2,1]) == 1
142+ getSafe 0 2 (A.fromList [3,2,1]) == 1
143− getWithDefault 0 5 (A.fromList [3,2,1]) == 0
143+ getSafe 0 5 (A.fromList [3,2,1]) == 0
144-}
144-}
145−getWithDefault : a -> Int -> Array a -> a
145+getSafe : a -> Int -> Array a -> a
146−getWithDefault default i array = if Native.Array.length array > i
146+getSafe default i array = if Native.Array.length array > i
147 then Native.Array.get i array else default
147 then Native.Array.get i array else default
148
148
149{-| Set the element at the index. Returns the updated array, or if the index is
149{-| Set the element at the index. Returns the updated array, or if the index is