Min / Max By (Expression) — skLambda

Addon: skLambda · Category: Expression · Since: 1.1.0

Syntax

[the] (lowest|minimum|min) [element] of %objects% by %object%

Description

Returns the element of a list with the smallest (`lowest`) or largest (`highest`) key, where a one-argument lambda pulls the key out of each element. Unlike `sorted by`, this hands back the element itself, not the key, and stops at a single result. Elements whose key is nothing are ignored. Ties keep the first element seen. An empty list (or one with no comparable keys) returns nothing.

Examples

# {_score} = lambda (p: player) -> number: return {_p}'s level
set {_top} to highest of all players by {_score}
set {_weakest} to lowest of {_mobs::*} by lambda (e: entity) -> number: health of {_e}

View source