Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

combinations for filters

Generates all combinations of size k from the input list.

Signature

> combinations {flags} (k)

Parameters

  • k: The size of each combination (k).

Input/output types:

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

Examples

Generate all 2-combinations

> [1 2 3] | combinations 2
╭───┬───────────╮
│ 0 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ │ 1 │ 2 │ │
│   │ ╰───┴───╯ │
│ 1 │ ╭───┬───╮ │
│   │ │ 0 │ 1 │ │
│   │ │ 1 │ 3 │ │
│   │ ╰───┴───╯ │
│ 2 │ ╭───┬───╮ │
│   │ │ 0 │ 2 │ │
│   │ │ 1 │ 3 │ │
│   │ ╰───┴───╯ │
╰───┴───────────╯

Generate combinations of lists

> [[a] [b] [c]] | combinations 2
╭───┬───────────────────╮
│ 0 │ ╭───┬───────────╮ │
│   │ │ 0 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ a │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ │ 1 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ b │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ ╰───┴───────────╯ │
│ 1 │ ╭───┬───────────╮ │
│   │ │ 0 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ a │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ │ 1 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ c │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ ╰───┴───────────╯ │
│ 2 │ ╭───┬───────────╮ │
│   │ │ 0 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ b │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ │ 1 │ ╭───┬───╮ │ │
│   │ │   │ │ 0 │ c │ │ │
│   │ │   │ ╰───┴───╯ │ │
│   │ ╰───┴───────────╯ │
╰───┴───────────────────╯

k > n yields an empty list

> [1 2] | combinations 3
╭────────────╮
│ empty list │
╰────────────╯