Flapjax JavaScript API
Documentation entry format:
length function or object name Type contract: String U Array -> Numbertype contract

In a type contract, an '->' denotes a function. For example, the function that describes length would take in a string and return a number, described as String -> Number. A function that takes in the length function and returns true would be described as (String -> Number) -> Boolean.

A function may have multiple arguments. For example, the max function takes in two numbers and returns one, described as Number * Number -> Number.

Some types may be parameterized by other types. For example, a function may expect an array of numbers and return boolean: Array Number -> Boolean. Sometimes this parameter type is generic, and there may be multiple. In such cases, a lowercase letter is used, starting at 'a', with each new type getting a new letter. A function to return the first element of an array would be represented by Array a -> a.

Sometimes, multiple types are valid for an argument. For example, length is applicable to both Strings and Arrays, described as: String U Array -> Number.

An argument may be optional. Slice will take an array, a starting index, and an ending index, returning the subarray defined by that interval. The ending index is optional: Array a * Number [* Number]

Often an argument may be either of a specific type, or an event or behaviour carrying a value of that type. Instead of writing Behaviour a U a, we write [Behaviour] a. Max may be defined for numbers and behaviours that are numbers, described as [Behaviour] Number * [Behaviour] Number -> [Behaviour] Number. Additionally, entire arguments may be optional. Max may be defined for two or three numbers, described as Number * Number [* Number] -> Number.

A function may take a homogeneous array as a parameter. MaxLen may be defined on an array composed of both arrays and strings (unioned), described as Array (String U Array) -> Number.

A function may expect an object with certain fields. DrawLine may expect two posn objects that have x and y fields that are numbers, described as {x: Number, y: Number} * {x: Number, y: Number} -> Void.

A function may take a variable number of arguments. The max function may take one or more numbers and returns the greatest, described as Number . Array Number -> Number.

global

If a library object is marked as global, and the library is set to use the global namespace, this object will be defined in the global namespace. In such cases, one can refer to the function directly without prefix, e.g.,

length('asdf')
. Alternatively, the same function is included as a field of the object returned from flapjax initialization, so one could write
var flapjax = flapjaxInit(...);
flapjax.length('asdf');
In this case, one can write length('asdf'). The functions in the returned object will be constructed in the same way as the public functions. The raw form of the functions are available from the 'util' field of the returned object, but this is only for expert users.

in String prototype

If a function is marked as being in the prototype of a particular object, it can be used with dot syntax for that object. For instance, because length is in the String prototype, you can write 'asdf'.length().

thread this as argument 0

If a method is in an object's prototype, that object may be used as an argument for that method, specified by this annotation. For length, this would be argument 0, so instead of length('asdf') it would be 'asdf'.length().

2 Given an array or string, return its length.
function or object description
Examples:Sample way to use the function
Get the length of the string 'asdf' Intent of sample
length('asdf');
4 return of sample
Variations: there may be similar ways of calling a function
LENGTH A variation of a function is similar to the original, but may have some of the arguments already filled in or have a different name for ease of use when using dot notation. If only its name is provided, then it is just a renaming of the original function. If it is different in any other way, then its properties, such as 'global' or 'in behaviour prototype', will be listed. global
return to top
return to top
return to top
return to top
return to top
return to top
return to top
$___defs Type contract: Array (Annotation * String * a)
global

Internal library function used for labeling functions for construction of the library. Useful for creating new libraries.

An Annotation is an object literal:

{
	[np: Boolean] - not public - do not add function to flapjax.pub, default false
	[b: Boolean] - behaviour - add function to behaviour prototype, default false
	[e: Boolean] - event - add function to event prototype, default false
	[c: Boolean] - context - first parameter to function is context, default false
	[a: Number] - argument - parameter position to replace with object when used in prototype, default: don't do it
}

Examples:
Add the identity function to the top level
$___defs.push([{}, 'identity', function (v} { return v;}])
undefined
return to top
return to top
AB Type contract: Maybe Event . Array (([[Behaviour] Array] [Behaviour] Object) U ([[Behaviour] Array] [Behaviour] Dom)) -> Behaviour Dom
global first argument is context when using explicit contexts

Make a time varying HTML anchor tag. More generally, <tag>B will create a time varying dom tag of type <tag>.


One argument, potentially a time varying one, may be an object containing the properties (and nested properties) of the tag. If an argument is a string or a time varying string, it is automatically turned into a TextNode. Arguments that are DOM nodes or time varying DOM nodes are inserted as children of the tag and updating is automatically handled.


Note: while AB may take arguments of type Behaviour, A cannot. AB is an optimized lift_b(A, ...).

Examples:
A link with no url nor text
AB();
A link with static url and text
A({href: 'http://www.site.com'}, 'link text');
A link with static url and text
AB({href: 'http://www.site.com'}, 'link text');
A link with static and time varying styles
AB({href: 'http://www.site.com'}, 'link text');
A link with time varying url and text
linkB = constant_b('http://www.site.com');
textB = constant_b('start text');
AB({href: linkB}, textB);
			
A time varying link in a paragraph.
linkB = constant_b('http://www.site.com');
textB = constant_b('start text');
PB(AB({href: linkB}, textB));
			
return to top
return to top
return to top
return to top
return to top
return to top
Behaviour Type contract: Maybe Event * Event a * a
global
Create a time varying value out of a starting value and an event stream of values that the time varying value will take.
Examples:
Create a time varying variable representing the time.
new Behavior(timer_e(1), 0);
Variations:
Behavior
global
Variations:
blind
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
return to top
return to top
return to top
Event Type contract: ( (Pulse a -> Void) * Pulse b -> Void) . Array Node b
global
Create a node in the dependency graph. It receives pulses from other nodes, and create new ones to send to later nodes that are dependent upon it. Note: event_e (internally referred to as createNode) is preferred due to context sensitivity, which is useful for keying. The main usecase here is for type inspection.
Examples:
Determine whether something is an Event stream.
receiver_e() instanceof Event;
			
true
Determine whether something is an Event stream.
timer_b() instanceof Event;
			
false
Given an event stream, create a new one sans events that are less than zero
new Event(
	[receiver_e()],
	function (sendNextPulse, pulse) {
		if (pulse.value > 0) { sendNextPulse(pulse); }
	});
			
[Object object] // Event
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
Hashtable Type contract:
global
Creates a hashtable that associates keys any type with at most one value. The returned hashtable has the following methods:
  • get: 'a -> 'b U Undefined
  • set: 'a * 'b -> Void
  • get variant put: 'a * 'b -> Void
  • clear: Void -> Void
  • remove: 'a -> Void
Examples:
Create a hashtable, insert a key-value pair with an empty object key and function value, and get it back:
 var h = new Hashtable();
 var k = {}; var v = function () {};
 h.set(k,v);
 h.get(k);
            
Function
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
Maybe Type contract: Maybe()
global
Maybe type. MaybeFull and MaybeEmpty variants.
Examples:
Check if a variable has Maybe type
x instanceof Maybe
true
return to top
MaybeEmpty Type contract: MaybeEmpty()
global

Variant of Maybe without a value.

Commonly used when explicitly specifying contexts.

Examples:
creation
var x = new MaybeEmpty();
inspection
x instanceof Maybe;
true
inspection
x instanceof MaybeEmpty;
true
inspection
x instanceof MaybeFull;
false
Variations:
maybeEmpty instance of MaybeEmpty
mmt instance of MaybeEmpty
return to top
MaybeFull Type contract: MaybeFull(a)
global
Variant of Maybe with a value
Examples:
creation
var x = new MaybeFull('1');
inspection
x instanceof Maybe;
true
inspection
x instanceof MaybeFull;
true
return value if has one
if (!(x instanceof Maybe)) { throw 'x not maybe type'; }
return (x instanceof MaybeFull)? x.value : 'x is MaybeEmpty so no value';
			
1
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
priorityQueue Type contract: { val: Array {k: Number, v: (->) }, insert: {k: Number, v: (->) }, isEmpty: -> Boolean, -> ( -> ) }
global
Behaviours and events are functions of other behaviours and events. There is a dependency graph representing this relationship. When creating a new type of node (representing an Event or Behaviour) in the graph, sometimes evaluation shouldn't occur until all children in a timestep update that need to do so. (The alternative would be doing something whenever any child updates, or waiting for literally all children to do so - some times it is not clear how many children will update, which is where the Priority Queue comes in). When a node should be evaluated topologically, notifications from children cause thunks to be placed into the PQ using the node rank is the key and the current evaluation stops. Whenever all computations halt, a check is made to the queue to see if any children should be propagated, at which point the lowest key value is removed and the process starts again.
Examples:
Insert a function to evaluate after the current pulses propagating finish but before any topological nodes or new events are treated
priorityQueue.insert({k: -1, v: function () { alert('hit'); });
			
return to top
return to top
return to top
Path Type contract: Path()
global

When a Pulse reaches a Node, the Pulse has a history of Nodes it has previously encoutered, represented by a Path.

Path is in the prototype of PathEnd, PathLink and PathBranch

return to top
PathBranch Type contract: PathBranch(Path, Path)
global
return to top
PathEnd Type contract: PathEnd()
global
Examples:
creation
new PathEnd();
return to top
PathLink Type contract: PathLink(a, Path)
global

A path with the most recent entry being a, and a history of previous elements recursively defined with Path

Typically, the first argument would be a Node in a dependency graph.

Examples:
creation
new PathLink(1, new PathEnd());
creation
new PathLink(1, new PathLink(2, new PathEnd()));
return to top
Pulse Type contract: Pulse(Number, Path, Number, a)
global

When a value changes in the dependency graph, it propagates to nodes dependent upon it so they can recompute.

Information beyond the actual value may be useful:

    Pulse(stamp, path, accuracy, value)
  • stamp: the time step the event occurred
  • path: nodes encountered previous to this node in the same timestep causing the current value
  • accuracy: number between 0 and 1 describing accuracy of value
  • value: the actual value being propagated
Examples:
get pulse value
(new Pulse(0, new PathEnd(), .5, 'hello')).value
'hello'
create an event stream transformer that returns an event stream with values that are increments of the values of its input event stream
var someStream_e = receiver();
var add1_e =
	function (evt_e) {
		return event_e(
			[evt_e],
			function (sendNextPulse, pulse_a) {
				var pulse_b =
					new Pulse(
						pulse_a.stamp,
						pulse_a.path,
						pulse_a.accuracy,
						pulse_a.value + 1);
				sendNextPulse(pulse_b);
			});
	};
add1_e(someStream_e);
			
[Object object] //type Event
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
return to top
addEvent Type contract: Dom * String DomEventEnum * (DomEvent -> a) -> Void
global
Register a listener for an event on a DOM node. The first argument is the DOM object on which to register an event, the second argument is the name of the event to register (ex: 'mouseover' or 'mouseout'), and the final argument is a callback to call whenever an event of the registered type occurs.
Examples:
Whenever the mouse moves over the node with id 'x', pop up a window with the text 'foo'
addEvent(document.getElementById('x'), 'mouseover', function (_) { alert('foo')});
undefined
return to top
return to top
and_e Type contract: Maybe Event * . Array [Event] Boolean -> Event Boolean
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Given an arbitrary amount of event streams, whenever all of them occur at the same time, send an event of the boolean operator 'and' folded over them.
Variations:
and
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
and_b Type contract: Maybe Event . Array [Behaviour] Boolean -> Behaviour Boolean
global in Behaviour prototype thread this as argument 0 first argument is context when using explicit contexts
Return true when all of the arguments are true, else false. If there are no arguments, the value is true. Any of the arguments may be behaviours.
Examples:
Represent a form being valid whenever its constituents are valid.
var constituent1B = constant_b(true);
var constituent2B = constant_b(true);
var constituent3B = constant_b(true);
var form1ValidB = and_b(constituent1B, constituent2B, constituent3B);
			
Variations:
and
in Behaviour prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
return to top
return to top
return to top
attachListener Type contract: Node * Node -> Void
in Event prototype thread this as argument 0
When the first parameter produces a value, send it to the second parameter. Repeatadly attaching the same node will mean repeat messages will be sent. This method does not impact rank calculations. For rank calculation, forward links (thisSendsTo) and backlinks (sendsToThis) should be modified.
Examples:
When 'a' receives a value, 'b' will also receive that value
var a = receiver_e();
var b = receiver_e();
a.attachListener(b);
			
When 'a' receives a value, 'b' will also receive that value
var a = receiver_e();
var b = receiver_e();
attachListener(a, b);
			
return to top
return to top
blind_e Type contract: Maybe Event * Event a * [Behaviour] Number -> Event a
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given an event stream and a window (possibly time varying), whenever an event occurs in the original stream, if there is no wait, send it in the created stream and create a wait such that all events that occur during it are not sent by the created stream.
Variations:
blind
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
calm_b Type contract: Maybe Event * Behaviour a * [Behaviour] Number -> Event a
globalin Behaviour prototype thread this as argument 0first argument is context when using explicit contexts
Create a new behaviour that is similar to another behaviour, except certain changes are ignored. When a change occurs, it is withheld for an interval. If another change occurs during this interval, ignore the first change and repeat the process for the second. If no other change occurs, the new behaviour will take on the value described by the change. Shorthand for B.changes.calm_e(interval).startsWith(B.valueNow());
Variations:
calm
in Behaviour prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
calm_e Type contract: Maybe Event * Event a * [Behaviour] Number -> Event a
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Given an event stream and a window value (possibly time varying), hold on to any event sent by the original stream. If the time specified by the windows passes with no new event occuring, send the held event (with the timestamp it was originally sent at). If another event occurs will waiting for the window to pass, discard the original event and hold on to the new one, resetting the window and repeating the whole process. This function is useful in modulating responses from event streams such as typing on the keyboard (waiting until there is a pause in typing).
Examples:
var window = 10;
var keyStreamE = receiver_e();
keyStreamE.calm_e(window);
			
var windowB = hold(receiver_e(), 10);
var keyStreamE = receiver_e();
keyStreamE.calm_e(windowB);
			
Variations:
calm
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
slice Type contract: Array a * Integer [* Integer] -> Array a
global
Returns a copy of a subsequence of an array. The first argument is the array to copy, the second argument the index of the first character to copy, and the third final argument the index at which to stop copying (so the copy does not include the element at this index). If the last argument is not included, it is defined to be the length of the array, so the entire array starting at an index is copied.
Examples:
Copy an array, except for its first element
slice([1,2,3], 1, [1,2,3].length)
[2,3]
Copy an array, except for its first element
slice([1,2,3], 1)
[2,3]
return to top
getURLParam Type contract: String -> String U undefined
global
Extract a parameter from the url and decode it. The url is stored during library initialization, so subsequent modifications to the url do not impact the return of this function.
Examples:
If the field 'name' with value "Mr. Sabatini" is in the url, as would be the case in ".../page?name=Mr.%20Sabatini", extract it.
getURLParam('name')
"Mr. Sabatini"
If the field 'name' with value "Mr. Sabatini" is in the url, as would be the case in ".../page?name=Mr.%20Sabatini", extract it.
$URL('name')
"Mr. Sabatini"
Variations:
$URL
return to top
getWebServiceObject_e Type contract: Maybe Event * Event WebServiceInfoObj -> Event
globalin Event prototype thread this as argument 0first argument is context when using explicit contexts

Note: This function is in a separate library, called fjws.js. To use it, you need to include the following tag in the head of your document:

< script type="text/javascript" src="/fjws/fjws.js" >
PATH is the path to the Flapjax source directory. You also need to include the following call at the beginning of your JavaScript loader function:
initFlapjaxWebServiceAPIs(flapjax, '#888888');
The first argument is the Flapjax object, i.e. the result of the call to flapjaxInit(). The second argument is the background color of your page.

initFlapjaxWebServiceAPIs also takes an optional third parameter. If you are running your own server, and the fjws directory is in a different location, then the third parameter is the path to the directory which contains fjws.js and the two necessary SWF files.

Given an eventstream of "WebServiceInfoObj"s, returns an eventstream consisting of the responses to each request. The type of request and type of response depend on the parameters of the WebServiceInfoObj. The library will either use a server-side proxy or a Flash object as a client-side proxy, as appropriate. As a result, requests can be made across domains, since using Flash and/or a proxy server effectively bypasses XmlHttpRequest's security policies.

WebServiceInfoObj is an object which obeys the following type signature:

url: string
[request: ("get" | "post" | "rawPost" | undefined)]
[fields: (object | undefined)]
[body: (string | undefined)]
[serviceType: ( "xml" | "jsonLiteral" | "plaintext" )]
[returnType: ( "xml" | "object" | undefined)]
[asynchronous: (boolean | undefined)]

Url is the simple URL for the web service. It should not include a question mark or any fields.

Fields is optional. If specified, and if the request-type is 'get' or 'post', then the request will automatically include them in the URL (for 'get') or the request (for 'post'). If request-type is 'get', 'post', or unspecified, then the value associated with each key must be a string, and will be automatically escaped.

Request is optional. If fields is not specified or is equal to {}, then request defaults to 'get'. If fields are given and non-empty, then request defaults to 'post'. If request is specified as 'get' or 'post', then the associated request is generated and used. If request is 'rawPost', then fields will be ignored, and body is sent as the body of the POST. If request is anything else, then it is treated as if it were not specified.

Body is optional. If specified, and if the request-type is 'rawPost', then it is sent as the body of the POST. If the request-type is anything else, it will be ignored.

ServiceType is optional. If not specified, it defaults to "object". If serviceType is "plaintext", then the response will not be parsed, but will be returned in an object of the form {value: string}.

ReturnType is optional. If not specified, it defaults to "object", which is a JavaScript value. "xml" can be specified if serviceType is "xml", in which case an XML object will be returned. If serviceType is not "xml" and return type is "xml", then the call is an error.

Asynchronous is optional. If not specified, it defaults to true. If false, then a method fetching this request will not return until the request is complete.

Examples:
Fetches an RSS feed from a URL specified in a text field.
var rssServiceInfoE = apply_e(function(v) {
  return {
    url: v,
    serviceType: 'xml'
  };
},extractValue_e("urlTextField");

var rssFeedE = getWebServiceObject_e(rssServiceInfoE);

var rssFeedB = rssFeedE.hold({title:'No page yet', items: {}});
Fetches the top 10 results on Yahoo Local for a query defined by a topic and a location, each in a text field.
var yahooServiceInfoE = apply_e(function (lcn,q) {
	return {
		url: 'http://api.local.yahoo.com/LocalSearchService/V1/localSearch',
		fields: {
			appid: 'flapjaxmashup',
			location: lcn,
			query: q},
		serviceType: 'xml',
		request: 'get'
	};
},extractValue_e('location'),extractValue_e('query'));

var yahooLocalE = getWebServiceObject_e(yahooServiceInfoE.calm(500));

var yahooLocalB = yahooLocalE.hold({ResultSet:{Result:[{'Title':'No results yet.'}]}});
return to top
readCookie Type contract: String -> String U Undefined
global
Given the name of a field in a cookie, extract its corresponding value from the cookie.
Examples:
Return the value of the username field in a cookie set by a server.
readCookie('username');
			
return to top
getElementsByClass Type contract: String ClassName [* Dom U null U undefined [* String DomNodeEnum]] -> Array Dom
global
Select DOM nodes in the DOM tree by their tag name. The first argument is the name of class to look up, the second argument the root node to start the search from (null or undefined default to document), and the final optional argument filters results by those that are of specific tag type (such as 'p' or 'div'). The W3C method getElementsByTagName may also be useful and is implemented by many browsers.
Examples:
Select all tags with the class 'speeches'
getElementsByClass('speeches')
Select all paragraph tags with the class 'speeches'
getElementsByClass('speeches', document, 'p')
Variations:
$$
return to top
swapDom Type contract: (Dom a U String) [* (Dom b U String)] -> Dom a
global
Remove a node from the dom tree and, if given a second node, put it in the first nodes place. If an input parameter is a string, it is treated as an ID and a DOM object in the document DOM tree with the same ID is used. Returns the node that was removed
Examples:
Remove node with id 'x'
swapDom('x')
Replace node with id 'x' with node with id 'y', and define the original node to be variable z
var z = swapDom(document.getElementById('x'), 'y')
return to top
member Type contract: a * Array b -> Boolean
global
Returns whether an element (using === comparison) occurs in an array
Examples:
Check if 2 is in an array
member(2, [224,2,4]);
true
return to top
map Type contract: ( (a_1 * ... * a_m) -> b) * (a_1 * ... * a_n)_1 * ... * (a_1 * ... * a_n)_m -> (b_1 * ... * b_n)
global
Given a function of n arguments, and n arrays of the same length, creates a new array of the same length as the inputs whose elements are defined by pointwise application of the function.
Examples:
Return the piece-wise sum:
map(function (x, y) { return x + y}, [1,2,3], [3,5,3]);
[4,7,6]
Given an array, return a new array describing which positions contain strings in the original array
map(function (x) { return typeof(x) == 'string'}, [1,'hello',2]);
[false,true,false]
Create an unordered list DOM object out of an array of text
UL.apply(this, map(LI, ['first string', 'second', 'last string']));
[DOM Object]
Variations:
forEach Same as map, except no return.
return to top
filter Type contract: (a -> Boolean) * Array a -> Array a
global
Only keep elements in an array that pass a predicate.
Examples:
Return a copy of an array, sans negative numbers
filter(function (v) { return v >= 0; }, [2,-3,0,2,-3]
[2,0,2]
return to top
return to top
fold Type contract: ((a1 * ... * am * b) -> b) * b * (a1...an)1 *... * (a1...an)m -> b
global
Also known as reduce in some languages. Note iteration occurs left to right.
Examples:
Find the length of an array
fold(function (_, acc) { return 1 + acc;}, 0, [1,2,3])
3
Find the sum of an array
fold(function (v, acc) { return v + acc;}, 0, [1,2,3])
6
Find the dot product of two arrays
fold(function (v1, v2, acc) { return v1 * v2 + acc;}, 0, [1,2,3], [3,4,5])
26
return to top
foldR Type contract: ((a1 * ... * am * b) -> b) * b * (a1...an)1 *... * (a1...an)m -> b
global
Same as fold, except iterate right to left.
return to top
getObj Type contract: String U Dom -> Dom
global
Given an id, search the dom tree for a node with a matching ID and return it.
Examples:
Find the node called 'myform'
getObj('myform');
Find the node called 'myform'
$('myform');
Find the node called 'myform': invoking '$' on a dom node will return that node, making it safe to call when you are unsure whether a parameter is a node or id.
$($('myform'));
Variations:
$
return to top
getObjs Type contract: . Array (String U Dom) -> {String: Dom}
global
Find multiple dom nodes by id, returning an object with fields corresponding to the input DOM IDs.
Examples:
find the value of a dom node with id 'y'
getObjs('x', 'y').y.value
find the value of a dom node with id 'y'
getObjs(LI({id: 'y'}, 'some node..')).y.value
Variations:
$O
return to top
getLabeledObjs Type contract: . Array( String U Array [String [*, String]]) -> Obj{String: Dom}
global
Find multiple dom nodes by id as in getObjs, but also optionally use different labels.
Examples:
Find the value of a dom node with id 'aVeryLongAndSillyName' using a label 'short'
document.appendChild(DIV({id: 'aVeryLongAndSillyName'}, 'my node'));
document.appendChild(DIV({id: 'okName'}, 'another node'));
getLabeledObjs('okName', ['aVeryLongAndSillyName', 'short']).short.value
Variations:
$L
return to top
getObjsA Type contract: (Array String ) U (. Array String) -> Array Dom
global
Find multiple dom nodes by id, returning an array
Examples:
Get the value of dom node with id 'y'
getObjsA['x', 'y', 'z'][1].value
Variations:
$A
return to top
return to top
isCommonPath Type contract: Path * Path -> Boolean
global
Returns whether 2 paths have a common value
Examples:
Shared value case:
isCommonPath(
	new PathLink(1, new PathLink(2, new PathEnd())),
	new PathLink(2, new PathEnd()));
			
true
No shared value:
isCommonPath(new PathEnd(), new PathEnd());
false
return to top
isCyclePath Type contract: Path -> Boolean
global

Returns true if a value occurs repeatadly on a path

Useful for detecting tight cycles propagating in the dependency graph

Examples:
isCyclePath(new PathLink(1, new PathLink(1, new PathEnd())));
true
isCyclePath(new PathLink(1, new PathLink(2, new PathEnd())));
false
return to top
propagatePulse Type contract: Pulse * Array Node ->
global

When a node has a new value, it generates a pulse that should be sent to nodes dependent upon it

Additionally, this method supports the opt-in topological evaluation strategy by checking the pulse queue when the recursive call finishes.

return to top
combinePulseFull Type contract: ( . Array Number - > Number) * ( . Array Path -> Path) * ( . Array Number -> Number) * ( . Array a -> b) * . Array Pulse -> Pulse
global
Given information from a collection of pulses, and ways of aggregating each type of information, create a new pulse
return to top
combinePulse Type contract: ( . (Array Obj) -> obj ) . (Array Pulse) -> Pulse
global
Given a collection of pulses and a way of aggregating their values, create a new pulse
return to top
return to top
updateParentRanks Type contract: Node -> Void
in Event prototype thread this as argument 0
Recalculates rank of current node and nodes dependent upon it in dependency rank. Useful when creating nodes that are actually multiple nodes and involve manually attaching dependency links.
Examples:
receiver_e().updateParentRanks();
updateParentRanks(receiver_e());
return to top
event_e Type contract: Maybe Node * Array Node a * ( (Pulse b ->) * (Pulse a) -> Void) -> Node b
global first argument is context when using explicit contexts
This is the main method for constructing event transformations. Creates an event (and thus node in the dependency graph) dependent upon other events. If the first argument is an instance of MaybeFull Event, this event will only fire when both dependent events occur and the MaybeFull Event occurs.
Examples:
Check type of an event_e
event_e([], function (_, __) {}) instanceof Event;
			
true
Check type of an event_e
event_e([], function (_, __) {}) instanceof Behaviour;
			
false
Given an event stream, return a new one, filtering out values that are smaller than the previously sent ones
var someEvent = receiver_e();
event_e(
	[someEvent],
	(function () {
		var prevAccepted = 0;
		return function (send, pulse) {
			if (p.value > prevAccepted) {
				prevAccepted = p.value;
				send(pulse);
			}
		};
	})());
			
return to top
topological_e Type contract: Maybe Node * Node a -> Node a
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Given a node in the dependency graph, create a new node dependent upon it. Whenever the child node propagates a pulse, the constructed node will also propagate it, but by defering it until the graph stabilizes and all topological nodes with a lesser rank have propagated their pulses. Useful in conjunction with raise_e in the definition of new types of nodes.
Variations:
topological
in Event prototype thread this as argument 0first argument is context when using explicit contexts
waitTopologically
in Event prototype thread this as argument 0first argument is context when using explicit contexts
return to top
return to top
return to top
raise_e Type contract: Maybe Node * Node a * Array Node b -> Node a
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Given a node, create a proxy for it that has a rank higher than the original and those in a set of nodes.
Examples:
receiver_e().raise_e([]);
raise_e(receiver_e(), []);
Variations:
raise
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
removeListener Type contract: Node * Node -> Boolean
in Event prototype thread this as argument 0
Remove a flow from one node to another. Only one such flow is removed; if two flows existed before the method call, one flow will exist after. Does not modify forward/back links for rank calculation (thisSendsTo, sendsToThis).
Examples:
var a = receiver_e();
var b = receiver_e();
a.attachListener(b);
a.removeListener(b);
				
When 'a' receives a value, 'b' will also receive that value
var a = receiver_e();
var b = receiver_e();
attachListener(a, b);
removeListener(a, b);
			
return to top
constant_e Type contract: Maybe Event * Array Event U Event * a -> Event a
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Given an event stream, return a new event stream that has an event everytime the original stream has one, except with a constant value.
Examples:
Given an input stream, whenever an event occurs in it, make an event with value 'hello'.
var inputStreamE = receiver_e();
var helloStreamE = inputStreamE.constant_e('hello');
			
Given an input stream, whenever an event occurs in it, make an event with value 'hello'.
var inputStreamE = receiver_e();
var helloStreamE = constant_e(inputStreamE, 'hello');
			
Given an input stream, whenever an event occurs in it, make an event with value 'hello'.
var inputStreamE = receiver_e();
var helloStreamE = inputStreamE.constant('hello');
			
Given an input stream, whenever an event occurs in it, make an event with value 'hello'.
var inputStreamE = receiver_e();
var helloStreamE = inputStreamE.replaceValue('hello');
			
Variations:
replaceValue_e
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given an event stream, return a new event stream that has an event everytime the original stream has one, except with a constant value.
constant
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
replaceValue
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
constant_b Type contract: Maybe Event * a -> Behaviour a
global in Behaviour prototype thread this as argument 0 first argument is context when using explicit contexts
Create a time varying value that always has the same value.
Variations:
constant
in Behaviour prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
return to top
return to top
key_e Type contract: Node * Array Node a * ( (Pulse b ->) * (Pulse a) -> Void) -> Node b
global
Queue pulses during a timestamp until the triggerNode sends a pulse, at which point release the stored pulses. If the trigger node was already activated for a timestamp, any pulse is instantly propagated. If no trigger occurs for a timesamp, queue the pulse for later. This type of node is used to avoid glitches and generally only deep in the library (event_e will call this function).
return to top
sync_e Type contract: Maybe Event * Array Event a -> Event Array a
global in Event prototype thread this as argument 0first argument is context when using explicit contexts
Treat an array of event streams as an array of FIFO queues. When all queues have at least one entry, pop an event value from each and create a new event that is an array of all the popped values.
Examples:
Create an event that is the time between mouseover and mouseout events
var mouseoverTimeE =
	receiver_e().transform_e(function(_){return (new Date()).getTime();});
var mouseoutTimeE =
	receiver_e().transform_e(function(_){return (new Date()).getTime();});
var resultE =
	sync_e(
		[mouseoverTimeE, mouseoutTimeE]).transform_e(
			function(arr){return arr[1] - arr[0];});
			
Variations:
sync
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
receiver_e Type contract: Maybe Event -> Event
global first argument is context when using explicit contexts
Create a new event that is not a function of any other events. Whenever it receives an event, it will propagate that event. Used commonly in conjunction with sendEvent.
Examples:
Create an event that will have periodically send the time. Create another event that is two times the one described above.
var someTimesE = receiver_e();
var fn = function () { someTimesE.sendEvent((new Date()).getTime()); };
setInterval(fn, 1000);
var doubledTimesE = someTimesE.transform_e(function (v) { return v * 2; });
			
Create an event that will have periodically send the time. Create another event that is two times the one described above.
var someTimesE = receiver_e();
var fn = function () { sendEvent(someTimesE, (new Date()).getTime()); };
setInterval(fn, 1000);
var doubledTimesE = someTimesE.transform_e(function (v) { return v * 2; });
			
return to top
sendEvent Type contract: Event * a [* Number] -> Voi
in Event prototype thread this as argument 0
Send a value, with a default accuracy of 1, to an event. Useful when interfacing with callbacks and in conjunction with receiver_e
Examples:
Create an event stream that doubles the values of its dependents, and start it off with an event of 2 (creating an event of value 4).
var doublerE = receiver_e().transform_e(function(v){return v * 2; });
doublerE.sendEvent(2);
			
Create an event stream that doubles the values of its dependents, and start it off with an event of 2 (creating an event of value 4).
var doublerE = receiver_e().transform_e(function(v){return v * 2; });
sendEvent(doublerE, 2);
			
return to top
not_e Type contract: Maybe Event * Event boolean -> Event boolean
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given a boolean event stream, return the negation of every event
Examples:
Given a boolean event, return the same value.
var sameE = receiver_e().not_e().not_e();
			
Variations:
not
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
filter_e Type contract: Maybe Event * (a -> Boolean) * Event a -> Event a
global in Event prototype thread this as argument 1 first argument is context when using explicit contexts
Given an event stream and a predicate, return a new event stream that has the events of the first that pass the predicate.
Examples:
Create an event stream that contains only positive numbers.
var positiveE = receiver_e().filter_e(function (v) { return v > 0; });
			
Variations:
filter
in Event prototype thread this as argument 1 first argument is context when using explicit contexts
return to top
return to top
merge_e Type contract: Maybe Event . Array Event a -> Event a
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given multiple event streams, turn them into one: whenever an event occurs on any of the inputs, propagate it.
Examples:
Define a color change to be red when a mouseover occurs and green when a mouse occurs.
var mouseoverE = receiver_e();
var mouseoutE = receiver_e();
var colorChangeE =
	merge_e(
		mouseoverE.constant_e('#F00'),
		mouseoutE.constant_e('#0F0'));
			
Variations:
merge
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
once_e Type contract: Maybe Event * Event a -> Event a
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given a stream of events, create a new stream that will send only the first event sent by the original event stream.
Variations:
once
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
skipFirst_e Type contract: contract
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given an event stream, return a stream that has the same events, except the first one is skipped.
Examples:
Skip the first two messages in a stream
var someEventE = receiver_e();
someEventE.skipFirst_e().skipFirst_e();
			
Variations:
skipFirst
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
collect_e Type contract: Maybe Event, Event a, b, (a * b -> b) -> Event b
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given an event stream, return a new event stream whose events are a fold (reduce) over the events previously occuring in the inputted event stream.
Examples:
Given an event stream, create a new event stream in which every event is the number of events that have occured in the original event stream.
var originalE = receiver_e();
var countE = originalE.collect_e(0, function (_, prevCount) { return prevCount + 1; });
			
Given an event stream, create a new event stream whose events occur at the same time as the original, but the values are 'on', 'off', alternately. The first event to occur should be 'on'.
var originalE = receiver_e();
var countE =
	originalE.collect_e(
		'off',
		function (_, prevVal) { return prevVal == 'on' ? 'off' : 'on'; });
			
Given an event stream, whenever an event occurs, if it is greater than the previous greatest value, send that value, else send the greatest value.
var originalE = receiver_e();
var countE =
	originalE.collect_e(
		0,
		function (curVal, prevGreatest) {
			return curVal > prevGreatest? curVal : prevGreatest ;
		});
			
Given an event stream where the value of each event is a name, create an event stream where every event is all of the names previously received. Create an entirely new array every time.
var originalE = receiver_e();
var countE =
	originalE.collect_e(
		[],
		function (curName, prevNames) { return [curName].concat(prevNames); });
			
Given an event stream where the value of each event is a name, create an event stream where every event is all of the names previously received. Reuse the previous array.
var originalE = receiver_e();
var countE =
	originalE.collect_e(
		[],
		function (curName, prevNames) {
			prevNames.push(curName);
			return prevNames;
		});
			
Variations:
collect
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
transformWithMemory
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
return to top
switch_e Type contract: Maybe Event * Event Event a -> Event a
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
Given an event stream of event streams, return an event stream whose events are those of the most recently arrived event stream.
Examples:
Given an event stream of dom objects, make an alert whenever the mouse moves over the most recently arrived DOM objects.
var domStreamE = receiver_e(); // every event is a DOM object
domStreamE.
	switch_e().
	extractEvent_e('mouseover').
	transform_e(function(_) { alert('hit!'); });
			
Variations:
forwardLatest
in Event prototype thread this as argument 0 first argument is context when using explicit contexts
return to top
return to top
if_e Type contract: Maybe Event * Event Boolean * Event a * Event a -> Event a
global in Event prototype thread this as argument 0 first argument is context when using explicit contexts
When an event occurs in the test position, if it is true, and in the same timestep an event occurs in th