A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.hashicorp.com/sentinel/docs/language/collection-operations below:

Sentinel Language - Collection Operations | Sentinel

Language: Collection Operations

Collection operations are expressions that are performed on a list or map to return a variation of the initial data.

At the moment, filter is the only collection operation available.

filter is a quantifier expression that returns a subset of the provided collection. Only elements whose filter body returns true will be returned. If any of the elements filter body returns undefined, the final result will be undefined.

Filter uses the same syntax as the any and all boolean expressions:

filter list as value { condition }      // Single-iterator, list
filter list as idx, value { condition } // Double-iterator, list

filter map as key { condition }         // Single-iterator, map
filter map as key, value { condition }  // Double-iterator, map

Examples:

l     = [1, 1, 2, 3, 5, 8]
evens = filter l as v { v % 2 is 0 } // [2, 8]

m           = { "a": "foo", "b": "bar" }
matched_foo = filter m as _, v { v is "foo" } // { "a": "foo" }

map is a quantifier expression that returns a list, regardless of the input collection type. Each element within the input collection is evaluted according to the map expression body and appended to the result.

l = [1, 2]
r = map l as v { v % 2 } // [false, true]

m = { "a": "foo", "b": "bar" }
r = map m as k, v { v } // ["foo", "bar"]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4