Add built-in event handlers (elm_log, elm_title, elm_redirect) and add Data.List.last
commit0934ab6e72882d2c00913b563978fa52d7e74b85
authorevancz <info@elm-lang.org>
dateThu 28 Jun 2012, 12:57 (14 years ago)
parentc94777f
core-js/Data.js+5−6
@@ -48,6 +48,7 @@ var Maybe = function() {
4848 };
4949}();
5050
51+/*
5152var String = function() {
5253
5354 function append(s1) { return function(s2) {
@@ -119,16 +120,14 @@ var String = function() {
119120 concatMap : concatMap,
120121 forall : forall,
121122 exists : exists,
122− /*
123− filter : filter,
124− take:,
125− drop:,
126− */
123+ //filter : filter,
124+ //take:,
125+ //drop:,
127126 toText : Value.toText,
128127 properEscape : Value.properEscape
129128 };
130129}();
131−
130+*/
132131return {String: {toText:Value.toText, properEscape:Value.properEscape},
133132 Char:Char,
134133 Maybe:Maybe,
core-js/Everything.js+6
@@ -1,6 +1,12 @@
11
22var eq = Value.eq;
33
4+Signal.addListener(document, 'elm_log', function(e) { console.log(e.value); });
5+Signal.addListener(document, 'elm_title', function(e) { document.title = e.value; });
6+Signal.addListener(document, 'elm_redirect', function(e) {
7+ if (e.value.length > 0) { window.location = e.value; }
8+ });
9+
410var includeGlobal = this;
511(function() {
612 var include = function(library) {
core-js/List.js+12
@@ -56,6 +56,17 @@ var List = function() {
5656 }
5757 return v[2];
5858 }
59+ function last(v) {
60+ if (v[0] !== "Cons") {
61+ throw "Error: 'last' only accepts lists of length greater than one.";
62+ }
63+ var out = v[1];
64+ while (v[0] === "Cons") {
65+ out = v[1];
66+ v = v[2];
67+ }
68+ return out;
69+ }
5970 function map(f) {
6071 return function(xs) {
6172 if (xs[0] === "Nil") { return xs; }
@@ -435,6 +446,7 @@ var List = function() {
435446 }
436447 return {head:head,
437448 tail:tail,
449+ last:last,
438450 map:map,
439451 foldl:foldl,
440452 foldr:foldr,
core-js/Prelude.js+1
@@ -55,6 +55,7 @@ var Prelude = function() {
5555 filter : Data.List.filter,
5656 head : Data.List.head,
5757 tail : Data.List.tail,
58+ last : Data.List.last,
5859 length : Data.List.length,
5960 reverse : Data.List.reverse,
6061 foldr : Data.List.foldr,
core-js/runtime/Signal.js+2−1
@@ -284,7 +284,8 @@ var Signal = function() {
284284 button:button};
285285 }();
286286
287− return {Mouse:Mouse,
287+ return {addListener:addListener,
288+ Mouse:Mouse,
288289 Keyboard:Keyboard,
289290 Time:Time,
290291 Window:Window,