4 var Nil = { ctor:'Nil' };
5 function Cons(hd,tl) { return { ctor:"Cons", _0:hd, _1:tl }; }
7 function throwError(f) {
8 throw new Error("Function '" + f + "' expects a non-empty list!");
11 function toArray(xs) {
13 while (xs.ctor === "Cons") {
20 function fromArray(arr) {
22 for (var i = arr.length; i--; ) {
23 out = Cons(arr[i], out);
28 function head(v) { v.ctor === "Nil" ? throwError('head') : return v._0; }
29 function tail(v) { v.ctor === "Nil" ? throwError('tail') : return v._1; }
32 if (xs.ctor === "Nil") { throwError('last'); }
34 while (xs.ctor === "Cons") {
41 function map(f) { return function(xs) {
43 while (xs.ctor === "Cons") {
47 return fromArray(arr);
51 function foldl(f) { return function(b) { return function(xs) {
53 while (xs.ctor === "Cons") {
62 function foldr(f) { return function(b) { return function(xs) {
63 var arr = toArray(xs);
65 for (var i = arr.length; i--; ) {
73 function foldl1(f) { return function(xs) {
74 xs.ctor === "Nil" ? throwError('foldl1') : return foldl(f)(xs._0)(xs._1);
78 function foldr1(f) { return function(xs) {
79 if (xs.ctor === "Nil") { throwError('foldr1'); }
80 var arr = toArray(xs);
82 for (var i = arr.length; i--; ) {
89 function scanl(f) { return function(b) { return function(xs) {
90 var arr = toArray(xs);
93 for (var i = 1; i < len; ++i) {
94 arr[i] = f(arr[i])(arr[i-1]);
96 return fromArray(arr);
101 function scanl1(f) { return function(xs) {
102 xs.ctor === "Nil" ? throwError('scanl1') : return scanl(f)(xs._0)(xs._1);
106 function filter(pred) { return function(xs) {
108 while (xs.ctor === "Cons") {
109 if (pred(xs._0)) { arr.push(xs._0); }
112 return fromArray(arr);
116 function length(xs) {
118 while (xs.ctor === "Cons") {
125 function reverse(xs) { return fromArray(toArray(xs).reverse()); }
127 function all(pred) { return function(xs) {
128 while (xs.ctor === "Cons") {
129 if (!pred(xs._0)) return false;
136 function any(pred) { return function(xs) {
137 while (xs.ctor === "Cons") {
138 if (pred(xs._0)) return true;
145 function zipWith(f) { return function(xs) { return function(ys) {
147 while (xs.ctor === "Cons" && ys.ctor === "Cons") {
148 arr.push(f(xs._0)(ys._0));
152 return fromArray(arr);
157 function zip(xs) { return function(ys) {
159 while (xs.ctor === "Cons" && ys.ctor === "Cons") {
160 arr.push(["Tuple2",xs._0,ys._0]);
164 return fromArray(arr);
169 return fromArray(toArray(xs).sort(function(a,b) { return a - b}));
172 function take(n) { return function(xs) {
174 while (xs.ctor === "Cons" && n > 0) {
179 return fromArray(arr);
183 function drop(n) { return function(xs) {
184 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