split list for filters

Split a list into multiple lists using a separator.

Signature

> split list {flags} (separator)

Flags

  • --regex, -r: separator is a regular expression, matching values that can be coerced into a string

Parameters

  • separator: the value that denotes what separates the list

Input/output types:

inputoutput
list<any>list<list<any>>

Examples

Split a list of chars into two lists

> [a, b, c, d, e, f, g] | split list d
╭───┬───────────╮
 0  ╭───┬───╮ 
     0  a  
     1  b  
     2  c  
    ╰───┴───╯ 
 1  ╭───┬───╮ 
     0  e  
     1  f  
     2  g  
    ╰───┴───╯ 
╰───┴───────────╯

Split a list of lists into two lists of lists

> [[1,2], [2,3], [3,4]] | split list [2,3]
╭───┬───────────────────╮
 0  ╭───┬───────────╮ 
     0  ╭───┬───╮  
         0  1   
         1  2   
        ╰───┴───╯  
    ╰───┴───────────╯ 
 1  ╭───┬───────────╮ 
     0  ╭───┬───╮  
         0  3   
         1  4   
        ╰───┴───╯  
    ╰───┴───────────╯ 
╰───┴───────────────────╯

Split a list of chars into two lists

> [a, b, c, d, a, e, f, g] | split list a
╭───┬───────────╮
 0  ╭───┬───╮ 
     0  b  
     1  c  
     2  d  
    ╰───┴───╯ 
 1  ╭───┬───╮ 
     0  e  
     1  f  
     2  g  
    ╰───┴───╯ 
╰───┴───────────╯

Split a list of chars into lists based on multiple characters

> [a, b, c, d, a, e, f, g] | split list --regex '(b|e)'
╭───┬───────────╮
 0  ╭───┬───╮ 
     0  a  
    ╰───┴───╯ 
 1  ╭───┬───╮ 
     0  c  
     1  d  
     2  a  
    ╰───┴───╯ 
 2  ╭───┬───╮ 
     0  f  
     1  g  
    ╰───┴───╯ 
╰───┴───────────╯