From 4043a99e0df9fab6791c485721c0046971754175 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 6 Apr 2025 14:52:59 -0400 Subject: Expand reducers so they support stuff like `(+.abs(): nums)` and `(==.length: texts)` --- docs/reductions.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/reductions.md b/docs/reductions.md index 7aadd30b..3cbb6d5d 100644 --- a/docs/reductions.md +++ b/docs/reductions.md @@ -69,10 +69,10 @@ a collection using the `_min_` and `_max_` infix operators. = 10 ``` -The `_min_` and `_max_` operators also support field and method call suffixes, -which makes it very easy to compute the argmin/argmax (or keyed -minimum/maximum) of a collection. This is when you want to get the minimum or -maximum value _according to some feature_. +Reducers also support field and method call suffixes, which makes it very easy +to compute the argmin/argmax (or keyed minimum/maximum) of a collection. This +is when you want to get the minimum or maximum value _according to some +feature_. ```tomo # Get the longest text: @@ -84,6 +84,22 @@ maximum value _according to some feature_. = -4 ``` +You can also use suffixes on other operators: + +```tomo +texts := ["x", "y", "z"] +>> (==: texts) += no +>> (==.length: texts) += yes +>> (+.length: texts) += 3 + +nums := [1, 2, -3] +>> (+.abs(): nums) += 6 +``` + ## Comprehensions Reductions work not only with iterable values (arrays, sets, integers, etc.), -- cgit v1.2.3