
try { now_loading('Array support.'); } catch (e) {}

//| S' <-- S : Array.grep(F)
//|
//| Build an array, S', which contains
//| all elements of S for which the functor F
//| returns a true value.
//|
Array.prototype.grep = function (f)
{
	var i;
	var arr = new Array();
	for (i=0; i<this.length; i++)
	{
		if (f(this[i], i)) { arr.push(this[i]); }
	}
	return arr;
}

//| S'' <-- S : Array.merge(S')
//|
//| Build an array S'', which contains all 
//| elements of S, followed by all elements
//| of S'
//|
Array.prototype.merge = function(a)
{
	var i;
	var n = new Array();
	for (i=0; i<this.length; i++) n.push(this[i]);
	for (i=0; i<a.length; i++) n.push(a[i]);
	return n;
}

//| M <-- S : Array.map(F)
//|
//| Build an array M, by application of the supplied
//| functor F on each element e in S, such that:
//|   if F(e) = null, no elements are appended to M
//|		if F(e) is an Array object, all the elements of 
//|     that Array object are appended to M
//|   if F(e) is any other value, that value is 
//|     appended to the M
//|
Array.prototype.map = function(f)
{
	var i;
	var arr = new Array();
	for (i=0; i<this.length; i++)
	{
		var v = f(this[i], i);
		if (v != null)
		{
			if (typeof(v) == 'object' && /function Array\(\)/.test(v.constructor)) 
			{ 
				arr.merge(v);
			}
			else
			{
				arr.push(v);
			}
		}
	}
	return arr;
}


