on master help sign in
Change to better get function names
commit3ffe7d036fdef2d56b1c23d8c0b9f7c9852ac003 authorChristian Widera <xash@posteo.de> dateMon 31 Mar 2014, 22:21 (13 years ago) parent358f38e
1 file changed+9−9
libraries/Array.elm+9−9
libraries/Array.elm+9−9
@@ -126,24 +126,24 @@ array length is unkown, use safeGet oder getWithDefault.
126126get : Int -> Array a -> a
127127get = Native.Array.get
128128
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.
130130
131− safeGet 2 (A.fromList [3,2,1]) == Just 2
132− safeGet 5 (A.fromList [3,2,1]) == Nothing
131+ getMaybe 2 (A.fromList [3,2,1]) == Just 2
132+ getMaybe 5 (A.fromList [3,2,1]) == Nothing
133133-}
134−safeGet : Int -> Array a -> Maybe a
135−safeGet i array = if Native.Array.length array > i
134+getMaybe : Int -> Array a -> Maybe a
135+getMaybe i array = if Native.Array.length array > i
136136 then Just (Native.Array.get i array)
137137 else Nothing
138138
139139{-| Get the element at the index. If the index is out of range, the given default
140140elementis returned.
141141
142− getWithDefault 0 2 (A.fromList [3,2,1]) == 1
143− getWithDefault 0 5 (A.fromList [3,2,1]) == 0
142+ getSafe 0 2 (A.fromList [3,2,1]) == 1
143+ getSafe 0 5 (A.fromList [3,2,1]) == 0
144144-}
145−getWithDefault : a -> Int -> Array a -> a
146−getWithDefault default i array = if Native.Array.length array > i
145+getSafe : a -> Int -> Array a -> a
146+getSafe default i array = if Native.Array.length array > i
147147 then Native.Array.get i array else default
148148
149149{-| Set the element at the index. Returns the updated array, or if the index is