StructFilter

This function creates a new Struct that returns all entries from an struct that match the given filter.

StructFilter( struct, filter [, parallel [, maxThreads ] ] )

Returns: Struct

Argument Description Default
struct
struct, required

struct to filter entries from

filter
function, required

filter can be a function/closure that implements the following constructor [function(any key,any value):boolean].

parallel
boolean, optional

execute closures parallel

maxThreads
number, optional

maximum number of threads executed, ignored when argument "parallel" is set to false

20

Examples

Member Function

animals = {
	cow: "moo",
	pig: "oink",
	snail: ""
};
// Show all animals
Dump(
	label: "All animals",
	var: animals
);
// Get animals that make noise
noisyAnimals = animals.filter(function(key) {
	// If the key has a value return true (noisy animal)
	if (animals[arguments.key].len()) {
		return true;
	}
	return false;
});
Dump(
	label: "Noisy Animals",
	var: noisyAnimals
);
// Get animals that are quiet
quietAnimals = animals.filter(function(key) {
	// If the key has a value return true (quiet animal)
	if (! animals[arguments.key].len()) {
		return true;
	}
	return false;
});
Dump(
	label: "Quiet Animals",
	var: quietAnimals
);

Non-Member Function

animals = {
	cow: "moo",
	pig: "oink",
	snail: ""
};
// Show all animals
Dump(
	label: "All animals",
	var: animals
);
// Get animals that make noise
noisyAnimals = StructFilter(animals, function(key) {
	// If the key has a value return true (noisy animal)
	if (Len(animals[arguments.key])) {
		return true;
	}
	return false;
});
Dump(
	label: "Noisy Animals",
	var: noisyAnimals
);
// Get animals that are quiet
quietAnimals = StructFilter(animals, function(key) {
	// If the key has a value return true (quiet animal)
	if (! Len(animals[arguments.key])) {
		return true;
	}
	return false;
});
Dump(
	label: "Quiet Animals",
	var: quietAnimals
);

See also