intersect

For filters.

Returns a list of unique elements present in both the input and the provided list.

Command Type

built-in

Signature

> intersect {flags} (other)

Parameters

  • other: The other list to intersect with.

Input/output types:

input output
list<any> list<any>
table table

Examples

Return the intersection of two lists

> [1 2 3 4] | intersect [3 4 5 6]
╭───┬───╮
│ 0 │ 3 │
│ 1 │ 4 │
╰───┴───╯

Intersection with no common elements

> [1 2 3] | intersect [4 5 6]
╭────────────╮
│ empty list │
╰────────────╯

Intersection of two tables

> [{a:1} {a:2} {a:3}] | intersect [{a:2} {a:3} {a:4}]
╭───┬───╮
│ # │ a │
├───┼───┤
│ 0 │ 2 │
│ 1 │ 3 │
╰───┴───╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.