@@ -111,7 +111,47 @@ Elm.Signal = function() {
111111 s1.kids.push(this);
112112 s2.kids.push(this);
113113 };
114+
115+ function delay(t) { return function(s) {
116+ var delayed = new input(s.value);
117+ function update(v) {
118+ setTimeout(function() { Dispatcher.notify(delayed.id,v); },t*1000);
119+ }
120+ function first(a) { return function(b) { return a; }; }
121+ return new lift(first, [delayed, new lift(update,[s])]);
122+ };
123+ }
114124
125+ var merge = function(s1,s2) {
126+ this.id = Guid.guid();
127+ this.value = s1.value;
128+ this.kids = [];
129+ this.next = null;
130+ this.count = 0;
131+ this.changed = false;
132+
133+ this.recv = function(timestep, changed, parentID) {
134+ this.count += 1;
135+ if (changed) {
136+ this.changed = true;
137+ if (parentID == s2.id && this.next === null) { this.next = s2.value; }
138+ if (parentID == s1.id) { this.next = s1.value; }
139+ }
140+
141+ if (this.count == 2) {
142+ if (this.changed) {
143+ this.value = this.next;
144+ this.next = null;
145+ }
146+ send(this, timestep, this.changed);
147+ this.changed = false;
148+ this.count = 0;
149+ }
150+ };
151+ s1.kids.push(this);
152+ s2.kids.push(this);
153+ };
154+
115155 return {
116156 constant : function(v) { return new input(v); },
117157 lift : function(f){return function(e){return new lift(f,[e]);};},
@@ -128,9 +168,14 @@ Elm.Signal = function() {
128168 return new fold(f,b,true,e); }; }; },
129169 foldp1 : function(f) { return function(e) {
130170 return new fold(f,function(x){return x;},true,e); }; },
171+ delay : delay,
172+ merge : function(s1) { return function(s2) { return new merge(s1,s2)}; },
131173 count : function(sig) {
132174 var incr = function(_){return function(c){return c+1;};};
133175 return new fold(incr,0,false,sig) },
176+ countIf : function(pred) { return function(sig) {
177+ var incr = function(x){return function(c){return pred(x) ? c+1 : c;};};
178+ return new fold(incr,0,false,sig) }; },
134179 keepIf : function(pred) { return function(base) { return function(sig) {
135180 return new dropIf(function(x) { return !pred(x)},base,sig); }; }; },
136181 dropIf : function(pred) { return function(base) { return function(sig) {