Skip to content

Commit 0bce2be

Browse files
authored
Add example of using the transpose operator with multiple items in element. (#4364)
Signed-off-by: Adam Talbot <[email protected]>
1 parent 5e3f2c0 commit 0bce2be

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/operator.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,47 @@ The above snippet prints:
19891989
[3, D]
19901990
```
19911991

1992+
If each element of the channel has more than 2 items, these will be flattened by the first item in the element and only emit an element when the element is complete:
1993+
1994+
```groovy
1995+
Channel.of(
1996+
[1, [1], ['A']],
1997+
[2, [1, 2], ['B', 'C']],
1998+
[3, [1, 2, 3], ['D', 'E']]
1999+
)
2000+
.transpose()
2001+
.view()
2002+
```
2003+
2004+
```
2005+
[1, 1, A]
2006+
[2, 1, B]
2007+
[2, 2, C]
2008+
[3, 1, D]
2009+
[3, 2, E]
2010+
```
2011+
2012+
To emit all elements, use `remainder: true`:
2013+
2014+
```groovy
2015+
Channel.of(
2016+
[1, [1], ['A']],
2017+
[2, [1, 2], ['B', 'C']],
2018+
[3, [1, 2, 3], ['D', 'E']]
2019+
)
2020+
.transpose(remainder: true)
2021+
.view()
2022+
```
2023+
2024+
```
2025+
[1, 1, A]
2026+
[2, 1, B]
2027+
[2, 2, C]
2028+
[3, 1, D]
2029+
[3, 2, E]
2030+
[3, 3, null]
2031+
```
2032+
19922033
Available options:
19932034

19942035
` by`

0 commit comments

Comments
 (0)