on master help sign in
Update function names
150e8d6Christian Widera
libraries/Array.elm+15−14
@@ -14,10 +14,10 @@ into a list before operating on it, and then turning it back into an array.
14@docs fill, fromList, concat, set, updates, push
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 toList, toIndexedList, indices, slice
18
18
19# Mapping, folding, zipping
19# Mapping, folding, zipping
20−@docs map, assocMap, foldl, foldr, zip, zipWith
20+@docs map, indexMap, foldl, foldr, zip, zipWith
21-}
21-}
22
22
23import Native.Array
23import Native.Array
@@ -41,10 +41,10 @@ fromList = List.foldl (Native.Array.push) Native.Array.empty
41
41
42{-| Create a list of elements from an array.
42{-| Create a list of elements from an array.
43
43
44− elements (fromList [3,5,8]) == [3,5,8]
44+ toList (fromList [3,5,8]) == [3,5,8]
45-}
45-}
46−elements : Array a -> [a]
46+toList : Array a -> [a]
47−elements = Native.Array.elements
47+toList = Native.Array.toList
48
48
49{-| Create a list of the possible indices of an array.
49{-| Create a list of the possible indices of an array.
50
50
@@ -53,12 +53,13 @@ elements = Native.Array.elements
53indices : Array a -> [Int]
53indices : Array a -> [Int]
54indices a = [0..Native.Array.length a - 1]
54indices a = [0..Native.Array.length a - 1]
55
55
56+-- TODO: make this a native function.
56{-| Create a list of tuples (Index, Element) from an array.
57{-| Create a list of tuples (Index, Element) from an array.
57
58
58− assocs (fromList [3,5,8]) == [(0,3), (1,5), (2,8)]
59+ toIndexedList (fromList [3,5,8]) == [(0,3), (1,5), (2,8)]
59-}
60-}
60−assocs : Array a -> [(Int, a)]
61+toIndexedList : Array a -> [(Int, a)]
61−assocs a = List.zip (indices a) (Native.Array.elements a)
62+toIndexedList a = List.zip (indices a) (Native.Array.toList a)
62
63
63{-| Apply a function on every element in an array.
64{-| Apply a function on every element in an array.
64
65
@@ -67,12 +68,12 @@ assocs a = List.zip (indices a) (Native.Array.elements a)
67map : (a -> b) -> Array a -> Array b
68map : (a -> b) -> Array a -> Array b
68map = Native.Array.map
69map = Native.Array.map
69
70
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.
71
72
72− assocMap (*) (fromList [5,5,5]) == fromList [0,5,10]
73+ indexedMap (*) (fromList [5,5,5]) == fromList [0,5,10]
73-}
74-}
74−assocMap : (Int -> a -> b) -> Array a -> Array b
75+indexedMap : (Int -> a -> b) -> Array a -> Array b
75−assocMap = Native.Array.assocMap
76+indexedMap = Native.Array.indexedMap
76
77
77{-| Reduce an array from the left.
78{-| Reduce an array from the left.
78
79
@@ -103,7 +104,7 @@ is longer, the extra elements are dropped.
103-}
104-}
104zipWith : (a -> b -> c) -> Array a -> Array b -> Array c
105zipWith : (a -> b -> c) -> Array a -> Array b -> Array c
105zipWith f a b =
106zipWith 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)
107
108
108{-| Return an empty array.
109{-| Return an empty array.
109
110
@@ -160,7 +161,7 @@ set = Native.Array.set
160 updates [(1,7),(2,8)] (fill 3 1) == fromList [1,7,8]
161 updates [(1,7),(2,8)] (fill 3 1) == fromList [1,7,8]
161-}
162-}
162updates : [(Int, a)] -> Array a -> Array a
163updates : [(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
164
165
165{-| Slice an array given a range. The selection is inclusive, so the last
166{-| Slice an array given a range. The selection is inclusive, so the last
166element in the selection will also be in the new array. This may change in the
167element 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) {
111 }
111 }
112
112
113 // Converts an array into a list of elements.
113 // Converts an array into a list of elements.
114− function elements(a) {
114+ function toList(a) {
115− return elements_(List.Nil, a);
115+ return toList_(List.Nil, a);
116 }
116 }
117
117
118− function elements_(list, a) {
118+ function toList_(list, a) {
119 for (var i = a.table.length - 1; i >= 0; i--) {
119 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]);
121 }
121 }
122 return list;
122 return list;
123 }
123 }
@@ -132,8 +132,8 @@ Elm.Native.Array.make = function(elm) {
132 return newA;
132 return newA;
133 }
133 }
134
134
135− // Maps a function over the indices and elements of an array.
135+ // Maps a function over the elements with their index as first argument.
136− function assocMap(f, a) {
136+ function indexedMap(f, a) {
137 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
137 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
138 if (a.height > 0) { newA.lengths = a.lengths; }
138 if (a.height > 0) { newA.lengths = a.lengths; }
139 for (var i = 0; i < a.table.length; i++) {
139 for (var i = 0; i < a.table.length; i++) {
@@ -474,14 +474,14 @@ Elm.Native.Array.make = function(elm) {
474
474
475 Elm.Native.Array.values = {
475 Elm.Native.Array.values = {
476 empty:empty,
476 empty:empty,
477− elements:elements,
477+ toList:toList,
478 concat:F2(concat),
478 concat:F2(concat),
479 push:F2(push),
479 push:F2(push),
480 slice:F3(slice),
480 slice:F3(slice),
481 get:F2(get),
481 get:F2(get),
482 set:F3(set),
482 set:F3(set),
483 map:F2(map),
483 map:F2(map),
484− assocMap:F2(assocMap),
484+ indexedMap:F2(indexedMap),
485 foldl:F3(foldl),
485 foldl:F3(foldl),
486 foldr:F3(foldr),
486 foldr:F3(foldr),
487 length:length
487 length:length
libraries/Native/Show.js+1−1
@@ -45,7 +45,7 @@ Elm.Native.Show.make = function(elm) {
45 }
45 }
46 return "(" + output.join(",") + ")";
46 return "(" + output.join(",") + ")";
47 } else if (v.ctor === "_Array") {
47 } else if (v.ctor === "_Array") {
48− var list = Array.elements(v);
48+ var list = Array.toList(v);
49 return "Array.fromList " + toString(list);
49 return "Array.fromList " + toString(list);
50 } else if (v.ctor === "::") {
50 } else if (v.ctor === "::") {
51 var output = '[' + toString(v._0);
51 var output = '[' + toString(v._0);