on master help sign in
Update function names
commit150e8d605c413b2ee0d3f5ac1e324b0e2cb910eb authorChristian Widera <xash@posteo.de> dateTue 1 Apr 2014, 00:05 (13 years ago) parent7175be1
3 files changed+24−23
libraries/Array.elm+15−14 libraries/Native/Array.js+8−8 libraries/Native/Show.js+1−1
libraries/Array.elm+15−14
@@ -14,10 +14,10 @@ into a list before operating on it, and then turning it back into an array.
1414@docs fill, fromList, concat, set, updates, push
1515
1616# Taking Arrays Apart
17−@docs elements, indices, assocs, slice
17+@docs toList, toIndexedList, indices, slice
1818
1919# Mapping, folding, zipping
20−@docs map, assocMap, foldl, foldr, zip, zipWith
20+@docs map, indexMap, foldl, foldr, zip, zipWith
2121-}
2222
2323import Native.Array
@@ -41,10 +41,10 @@ fromList = List.foldl (Native.Array.push) Native.Array.empty
4141
4242{-| Create a list of elements from an array.
4343
44− elements (fromList [3,5,8]) == [3,5,8]
44+ toList (fromList [3,5,8]) == [3,5,8]
4545-}
46−elements : Array a -> [a]
47−elements = Native.Array.elements
46+toList : Array a -> [a]
47+toList = Native.Array.toList
4848
4949{-| Create a list of the possible indices of an array.
5050
@@ -53,12 +53,13 @@ elements = Native.Array.elements
5353indices : Array a -> [Int]
5454indices a = [0..Native.Array.length a - 1]
5555
56+-- TODO: make this a native function.
5657{-| Create a list of tuples (Index, Element) from an array.
5758
58− assocs (fromList [3,5,8]) == [(0,3), (1,5), (2,8)]
59+ toIndexedList (fromList [3,5,8]) == [(0,3), (1,5), (2,8)]
5960-}
60−assocs : Array a -> [(Int, a)]
61−assocs a = List.zip (indices a) (Native.Array.elements a)
61+toIndexedList : Array a -> [(Int, a)]
62+toIndexedList a = List.zip (indices a) (Native.Array.toList a)
6263
6364{-| Apply a function on every element in an array.
6465
@@ -67,12 +68,12 @@ assocs a = List.zip (indices a) (Native.Array.elements a)
6768map : (a -> b) -> Array a -> Array b
6869map = Native.Array.map
6970
70−{-| Apply a function with an index on every element in an array.
71+{-| Apply a function on every element with its index as first argument.
7172
72− assocMap (*) (fromList [5,5,5]) == fromList [0,5,10]
73+ indexedMap (*) (fromList [5,5,5]) == fromList [0,5,10]
7374-}
74−assocMap : (Int -> a -> b) -> Array a -> Array b
75−assocMap = Native.Array.assocMap
75+indexedMap : (Int -> a -> b) -> Array a -> Array b
76+indexedMap = Native.Array.indexedMap
7677
7778{-| Reduce an array from the left.
7879
@@ -103,7 +104,7 @@ is longer, the extra elements are dropped.
103104-}
104105zipWith : (a -> b -> c) -> Array a -> Array b -> Array c
105106zipWith f a b =
106− fromList <| List.zipWith f (Native.Array.elements a) (Native.Array.elements b)
107+ fromList <| List.zipWith f (Native.Array.toList a) (Native.Array.toList b)
107108
108109{-| Return an empty array.
109110
@@ -160,7 +161,7 @@ set = Native.Array.set
160161 updates [(1,7),(2,8)] (fill 3 1) == fromList [1,7,8]
161162-}
162163updates : [(Int, a)] -> Array a -> Array a
163−updates assocs array = List.foldl (uncurry Native.Array.set) array assocs
164+updates us array = List.foldl (uncurry Native.Array.set) array us
164165
165166{-| Slice an array given a range. The selection is inclusive, so the last
166167element in the selection will also be in the new array. This may change in the
libraries/Native/Array.js+8−8
@@ -111,13 +111,13 @@ Elm.Native.Array.make = function(elm) {
111111 }
112112
113113 // Converts an array into a list of elements.
114− function elements(a) {
115− return elements_(List.Nil, a);
114+ function toList(a) {
115+ return toList_(List.Nil, a);
116116 }
117117
118− function elements_(list, a) {
118+ function toList_(list, a) {
119119 for (var i = a.table.length - 1; i >= 0; i--) {
120− list = a.height == 0 ? List.Cons(a.table[i], list) : elements_(list, a.table[i]);
120+ list = a.height == 0 ? List.Cons(a.table[i], list) : toList_(list, a.table[i]);
121121 }
122122 return list;
123123 }
@@ -132,8 +132,8 @@ Elm.Native.Array.make = function(elm) {
132132 return newA;
133133 }
134134
135− // Maps a function over the indices and elements of an array.
136− function assocMap(f, a) {
135+ // Maps a function over the elements with their index as first argument.
136+ function indexedMap(f, a) {
137137 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
138138 if (a.height > 0) { newA.lengths = a.lengths; }
139139 for (var i = 0; i < a.table.length; i++) {
@@ -474,14 +474,14 @@ Elm.Native.Array.make = function(elm) {
474474
475475 Elm.Native.Array.values = {
476476 empty:empty,
477− elements:elements,
477+ toList:toList,
478478 concat:F2(concat),
479479 push:F2(push),
480480 slice:F3(slice),
481481 get:F2(get),
482482 set:F3(set),
483483 map:F2(map),
484− assocMap:F2(assocMap),
484+ indexedMap:F2(indexedMap),
485485 foldl:F3(foldl),
486486 foldr:F3(foldr),
487487 length:length
libraries/Native/Show.js+1−1
@@ -45,7 +45,7 @@ Elm.Native.Show.make = function(elm) {
4545 }
4646 return "(" + output.join(",") + ")";
4747 } else if (v.ctor === "_Array") {
48− var list = Array.elements(v);
48+ var list = Array.toList(v);
4949 return "Array.fromList " + toString(list);
5050 } else if (v.ctor === "::") {
5151 var output = '[' + toString(v._0);