Predicate Passes (Condition) — skLambda

Addon: skLambda · Category: Condition · Since: 0.0.3-alpha

Syntax

[not] [(all|any|none) of] %objects% pass[es] [for %-objects%]

Description

Treats a lambda as a predicate: invokes it with the given arguments and checks whether it returned true.

With a list of lambdas, an optional quantifier decides how many must pass: `all of` (the default) passes only if **every** predicate passes. `{checks::*} passes` and`all of {checks::*} passes` mean the same thing. `any of` passes if **at least one** predicate passes (OR semantics). `none of` passes if **no** predicate passes. `at least N of`, `at most N of`, and `exactly N of` pass when the number of passing predicates is at least, at most, or exactly N.

The negated forms (`doesn't pass`, or a leading `not`) invert the result. A lambda that isn't a predicate (doesn't return true) counts as not passing. An empty list never passes `all of`/`any of` and always passes `none of`.

Predicates run in their own context, so write them to take the value(s) they test as parameters and supply them after `for`.

Examples

set {is-op} to lambda (p: player): {_p} is op
if {is-op} passes for player:
	send "you're staff" to player

if any of {is-mod::*} passes for {_p}:
	send "mod access" to {_p}

if none of {is-banned::*} passes for {_p}:
	send "welcome" to {_p}

if at least 2 of {requirements::*} passes for {_p}:
	send "you qualify" to {_p}

if not {is-op} passes for {_p}:
	send "not opped" to {_p}

listen for block break where {is-stone} passes for event-block:
	on trigger: send "stone!" to event-player

View source