ARRAY_SPLIT
Function
Split the input array into multiple subarrays according to given boolean flags.
- Splitting rule (left to right): for arr=[a1,a2,...,an]andflags=[f1,f2,...,fn], at every position wherefi==true, split betweenaianda(i-1).- For example, with arr=[3, 4, 5]andflags=[false, true, false], the second flag is true, so split between the first and second elements, resulting in two subarrays[3]and[4,5].
 
- For example, with 
Syntax
- ARRAY_SPLIT(arr, flags)
- ARRAY_SPLIT(lambda, arr0, ...)
- ARRAY_SPLIT(lambda, arr0, ...)is equivalent to- ARRAY_SPLIT(arr0, ARRAY_MAP(lambda, arr0, ...))
Parameters
- arr:- ARRAY<T>.
- flags:- ARRAY<BOOLEAN>, whose length must match that of- arrrow by row.- truemeans split between the current position and the next element.
- arr0, ...: one or more- ARRAY<T>.
- lambda: a- lambdaexpression applied to- arr0, ...to produce- flags, which are then used for splitting.
Return value
- Returns ARRAY<ARRAY<T>>. Elements of inner arrays are the same as those ofarr.
- If the element counts of arrandflagsdo not match, an error is thrown.
Usage notes
- If a position in flagsisNULL, it is treated as no split (equivalent tofalse).
- The splitting rule of ARRAY_SPLITis: at each position wherefi==true, split betweenaianda(i-1).
- The splitting rule of ARRAY_REVERSE_SPLITis: at each position wherefi==true, split betweenaianda(i+1).
Examples
- 
Basic splitting: at each trueposition, split from the left side neighbor.- ARRAY_SPLIT([1,2,3,4,5], [false,true,false,true,false])->- [[1], [2, 3], [4, 5]]
- ARRAY_SPLIT(['a','b','c'], [false,false,false])->- [['a','b','c']]
 
- 
With NULLinflags:NULLis treated the same asfalse(no split).- ARRAY_SPLIT([1,NULL,3], [false,null,false])->- [[1,[NULL,3]]
 
- 
lambda= x -> x-1applied toarr0=[1, 2, 3]producesflags=[0,1,2], equivalent toflags=[false,true,true]- ARRAY_SPLIT(x->x-1, [1, 2, 3])is equivalent to- ARRAY_SPLIT([1, 2, 3], [false,true,true])->- [[1], [2], [3]]
 
- 
lambda= (x,y) -> x-yapplied toarr0=[1, 2, 3]andarr1=[0,1,2]producesflags=[true,true,true]- ARRAY_SPLIT((x,y) -> x-y, [1, 2, 3], [0, 1, 2])is equivalent to- ARRAY_SPLIT([1, 2, 3], [true,true,true])->- [[1], [2], [3]]