StructEvery

This function calls a given closure/function with every element in a given struct and returns true, if all of the closure calls returns true.

Returns: boolean

Usage

StructEvery( struct, closure [, parallel [, maxThreads ] ] )

Arguments

Argument Description Default
struct
(struct, required)

struct to iterate

closure
(function, required)

function/closure that implements the following constructor [function(string key, any value[array array]):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",
	cat: "meow"
};

// Use every() to iterate over keys in struct. Closure returns true/false.
allAnimalsAreNoisy = animals.every(function(key) {
	// If the key has a value return true (noisy animal)
	if (animals[arguments.key].len()) {
		return true;
	}

	return false;
});

Dump(
	label: "allAnimalsAreNoisy",
	var: allAnimalsAreNoisy
);

// Use every() to iterate over keys in struct. Closure returns true/false.
allAnimalsAreQuiet = animals.every(function(key) {
	// If the key is blank return true (quiet animal)
	if (! animals[arguments.key].len()) {
		return true;
	}

	return false;
});

Dump(
	label: "allAnimalsAreQuiet",
	var: allAnimalsAreQuiet
);

Non-Member Function

animals = {
	cow: "moo",
	pig: "oink",
	cat: "meow"
};

// Use StructEvery() to iterate over keys in struct. Closure returns true/false.
allAnimalsAreNoisy = StructEvery(animals, function(key) {
	// If the key has a value return true (noisy animal)
	if (Len(animals[arguments.key])) {
		return true;
	}

	return false;
});

Dump(
	label: "allAnimalsAreNoisy",
	var: allAnimalsAreNoisy
);

// Use StructEvery() to iterate over keys in struct. Closure returns true/false.
allAnimalsAreQuiet = StructEvery(animals, function(key) {
	// If the key is blank return true (quiet animal)
	if (! Len(animals[arguments.key])) {
		return true;
	}

	return false;
});

Dump(
	label: "allAnimalsAreQuiet",
	var: allAnimalsAreQuiet
);

See also