Task

Take a combined set of elements and apply a function to each element.




function map(f,a) {
	nr = rows(a)
	nc = cols(a)
	b = J(nr,nc,.)
	for (i=1;i<=nr;i++) {
		for (j=1;j<=nc;j++) b[i,j] = (*f)(a[i,j])
	}
	return(b)
}
 
function maps(f,a) {
	nr = rows(a)
	nc = cols(a)
	b = J(nr,nc,"")
	for (i=1;i<=nr;i++) {
		for (j=1;j<=nc;j++) b[i,j] = (*f)(a[i,j])
	}
	return(b)
}
 
function square(x) {
	return(x*x)
}