2module Native.List where
10 var Nil = { ctor:'Nil' };
11 function Cons(hd,tl) { return { ctor:"Cons", _0:hd, _1:tl }; }
13 function throwError(f) {
14 throw new Error("Function '" + f + "' expects a non-empty list!");
17 function toArray(xs) {
19 while (xs.ctor === "Cons") {
26 function fromArray(arr) {
28 for (var i = arr.length; i--; ) {
29 out = Cons(arr[i], out);
34 function range(lo,hi) {
37 do { lst = Cons(hi,lst) } while (hi-->lo);
42 function append(xs,ys) {
43 if (typeof xs === "string") { return xs.concat(ys); }
44 if (xs.ctor === "Nil") { return ys; }
45 var root = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
48 while (xs.ctor==="Cons") {
49 curr._1 = Elm.Native.List.Cons(xs._0. Elm.Native.List.Nil);
57 function head(v) { return v.ctor === "Nil" ? throwError('head') : v._0; }
58 function tail(v) { return v.ctor === "Nil" ? throwError('tail') : v._1; }
61 if (xs.ctor === "Nil") { throwError('last'); }
63 while (xs.ctor === "Cons") {
72 while (xs.ctor === "Cons") {
76 return fromArray(arr);
79 function foldl(f, b, xs) {
81 while (xs.ctor === "Cons") {
88 function foldr(f, b, xs) {
89 var arr = toArray(xs);
91 for (var i = arr.length; i--; ) {
97 function foldl1(f, xs) {
98 return xs.ctor === "Nil" ? throwError('foldl1') : foldl(f, xs._0, xs._1);
101 function foldr1(f, xs) {
102 if (xs.ctor === "Nil") { throwError('foldr1'); }
103 var arr = toArray(xs);
105 for (var i = arr.length; i--; ) {
106 acc = A2(f, arr[i], acc);
111 function scanl(f, b, xs) {
112 var arr = toArray(xs);
114 var len = arr.length;
115 for (var i = 1; i < len; ++i) {
116 arr[i] = A2(f, arr[i], arr[i-1]);
118 return fromArray(arr);
121 function scanl1(f, xs) {
122 return xs.ctor === "Nil" ? throwError('scanl1') : scanl(f, xs._0, xs._1);
125 function filter(pred, xs) {
127 while (xs.ctor === "Cons") {
128 if (pred(xs._0)) { arr.push(xs._0); }
131 return fromArray(arr);
134 function length(xs) {
136 while (xs.ctor === "Cons") {
143 function reverse(xs) { return fromArray(toArray(xs).reverse()); }
145 function all(pred, xs) {
146 while (xs.ctor === "Cons") {
147 if (!pred(xs._0)) return false;
153 function any(pred, xs) {
154 while (xs.ctor === "Cons") {
155 if (pred(xs._0)) return true;
161 function zipWith(f, xs, ys) {
163 while (xs.ctor === "Cons" && ys.ctor === "Cons") {
164 arr.push(A2(f, xs._0, ys._0));
168 return fromArray(arr);
171 function zip(xs, ys) {
173 while (xs.ctor === "Cons" && ys.ctor === "Cons") {
174 arr.push({ ctor:'Tuple2', _0:xs._0, _1:ys._0 });
178 return fromArray(arr);
182 return fromArray(toArray(xs).sort(function(a,b) { return a - b}));
185 function take(n, xs) {
187 while (xs.ctor === "Cons" && n > 0) {
192 return fromArray(arr);
195 function drop(n, xs) {
196 while (xs.ctor === "Cons" && n > 0) {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list