Skip to main content
Version: v1.18.0

yield

Operator

yield emit values from expressions

Synopsis

[yield] <expr> [, <expr>...]

Description

The yield operator produces output values by evaluating one or more expressions on each input value and sending each result to the output in left-to-right order. Each <expr> may be any valid Zed expression.

The yield keyword is optional since it is an implied operator.

Examples

Hello, world

echo null | zq -z 'yield "hello, world"' -

=>

"hello, world"

Yield evaluates each expression for every input value

echo 'null null null' | zq -z 'yield 1,2' -

=>

1
2
1
2
1
2

Yield typically operates on its input

echo '1 2 3' | zq -z 'yield this*2+1' -

=>

3
5
7

Yield is often used to transform records

echo '{a:1,b:2}{a:3,b:4}' | zq -z 'yield [a,b],[b,a] | collect(this)' -

=>

[[1,2],[2,1],[3,4],[4,3]]