| | |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| **_Description:_** | An anonymous function, often called a lambda function, which accepts parameters and _closes over_ (i.e., uses) variables from outside its scope |
| **_Annotation:_** | `closure` |
| **_Literal Syntax:_** | `{\|args\| expressions }` |
| **_See also:_** | [Language Reference - Closure](/lang-guide/chapters/types/basic_types/closure.md) |
Simple example:
This closure returns a boolean result of the comparison and then uses it in a `filter` command to return all values greater than 5.
```nu
let compare_closure = {|a| $a > 5 }
let original_list = [ 40 -4 0 8 12 16 -16 ]
$original_list | filter $compare_closure
# => ╭───┬────╮
# => │ 0 │ 40 │
# => │ 1 │ 8 │
# => │ 2 │ 12 │
# => │ 3 │ 16 │
# => ╰───┴────╯
```
Closures are a useful way to represent code that can be executed on each row of data via [filters](/lang-guide/chapters/filters/00_filters_overview.md)
### Binary data
| | |
| --------------------- | --------------------------------------------------------------------------- |
| **_Description:_** | Represents binary data |
| **_Annotation:_** | `binary` |
| **_Literal Syntax:_** | `0x[ffffffff]` - hex-based binary representation |
| | `0o[1234567]` - octal-based binary representation |
| | `0b[10101010101]` - binary-based binary representation |
| **_See also:_** | [Language Guide - Binary](/lang-guide/chapters/types/basic_types/binary.md) |
Binary data, like the data from an image file, is a group of raw bytes.
Simple example - Confirm that a JPEG file starts with the proper identifier:
```nu
open nushell_logo.jpg
| into binary
| first 2
| $in == 0x[ff d8]
# => true
```
## Structured Data Types
Nushell includes a collection of structured data types that can contain the primitive types above. For example, instead of a single `float`, structured data gives us a way to represent multiple `float` values, such as a `list` of temperature readings, in the same value. Nushell supports the following structured data types:
### Lists
| | |
| --------------------- | ------------------------------------------------------------------------------- |
| **_Description:_** | Ordered sequence of zero or more values of any type |
| **_Annotation:_** | `list` |
| **_Literal Syntax:_** | See [Language Guide - List](/lang-guide/chapters/types/basic_types/list.md) |
| **_See Also:_** | [Working with Lists](./working_with_lists.md) |
| | [Navigating and Accessing Structured Data](/book/navigating_structured_data.md) |
Simple example:
```nu
[Sam Fred George]
# => ╭───┬────────╮
# => │ 0 │ Sam │
# => │ 1 │ Fred │
# => │ 2 │ George │
# => ╰───┴────────╯
```
### Records
| | |