> For the complete documentation index, see [llms.txt](https://docs.urbit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.urbit.org/hoon/stdlib/2m.md).

# 2m: Container from Noun

Functions for creating typed containers (lists, maps, sets) from raw nouns.

## `+ly` <a href="#ly" id="ly"></a>

A `+list` from raw `$noun`.

Takes a null-terminated `$noun` and produces a `+list`.

#### Accepts

`.a` is a null-terminated `$noun`.

#### Produces

A `+list`.

#### Source

```hoon
++  ly
  le:nl
```

#### Examples

```
> (ly [1 2 3 ~])
~[1 2 3]
```

```
> (ly "abc")
~['a' 'b' 'c']
```

#### Discussion

`+ly` is an alias for `+le:nl`.

***

## `+my` <a href="#my" id="my"></a>

Map from raw `$noun`.

Takes a null-terminated `$noun` and produces a `+map`.

#### Accepts

`.a` is a `$noun` composed of ordered pairs and terminated with `~`.

#### Produces

A `+map`.

#### Source

```hoon
++  my
  my:nl
```

#### Examples

```
> (my [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]
```

#### Discussion

Note that `+my` is an alias for `+my:nl`.

***

## `+sy` <a href="#sy" id="sy"></a>

Set from raw `$noun`.

Takes a null-terminated `$noun` and produces a `+set`.

#### Accepts

`.a` is a null-terminated `$noun`.

#### Produces

A `+set`.

#### Source

```hoon
++  sy
  si:nl
```

#### Examples

```
> (sy [1 2 3 ~])
[n=2 l={1 3} r={}]
```

```
> (sy (ly [1 2 3 ~]))
[n=2 l={1 3} r={}]
```

```
> (sy "abc")
[n='b' l={'a' 'c'} r={}]
```

#### Discussion

`+sy` is an alias for `+si:nl`.

***

## `+nl` <a href="#nl" id="nl"></a>

Noun-to-container operations.

Core whose arms contain functions that create various typed `$noun`s from raw `$noun`s.

#### Source

```hoon
++  nl
  |%
```

***

### `+le:nl` <a href="#lenl" id="lenl"></a>

Construct `+list`.

Takes a null-terminated `$noun` and produces a `+list`.

#### Accepts

`.a` is a null-terminated `$noun`.

#### Produces

A `+list`.

#### Source

```hoon
++  le
  |*  a=(list)
  ^+  =<  $
    |@  ++  $  ?:(*? ~ [i=(snag 0 a) t=$])
    --
  a
```

#### Examples

```
> (le:nl [1 2 3 ~])
~[1 2 3]
```

```
> (le:nl "abc")
~['a' 'b' 'c']
```

***

### `+my:nl` <a href="#mynl" id="mynl"></a>

Construct `+map`.

Takes a null-terminated `$noun` and produces a `+map` of the same type of the `.p` and `.q` passed in.

#### Accepts

`.a` is a `$noun` composed of ordered pairs and terminated with `~`.

#### Produces

A `+map`.

#### Source

```hoon
++  my
  |*  a=(list (pair))
  =>  .(a ^+((le a) a))
  (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
```

#### Examples

```
> (my:nl [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]
```

***

### `+si:nl` <a href="#sinl" id="sinl"></a>

Construct `+set`.

Takes a null-terminated `$noun` and produces a `+set`.

#### Accepts

`.a` is a null-terminated `$noun`.

#### Produces

A `+set`.

#### Source

```hoon
++  si
  |*  a=(list)
  =>  .(a ^+((le a) a))
  (~(gas in `(set _i.-.a)`~) a)
```

#### Examples

```
> (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
[n=['b' [2 3]] l={['a' 1]} r={}]
```

***

### `+snag:nl` <a href="#snagnl" id="snagnl"></a>

Index.

Produces the element at the index `.a` of null-terminated `$noun` `.b` and failing if the `$noun` is null. `+list`s are 0-indexed.

#### Accepts

`.a` is a `$noun`.

`.b` is a null-terminated `$noun`.

#### Produces

A `$noun`.

#### Sources

```hoon
++  snag
  |*  [a=@ b=(list)]
  ?~  b
    ~_  leaf+"snag-fail"
    !!
  ?:  =(0 a)  i.b
  $(b t.b, a (dec a))
```

#### Examples

```
> =b [[2 3] [1 4] ~]

> (snag:nl 0 b)
[2 3]

> (snag:nl 2 b)
! snag-fail
! exit
```

***

### `+weld:nl` <a href="#weldnl" id="weldnl"></a>

Concatenate.

Produces a `+list` that is the concatenation of null-terminated `$noun`s `.a` and `.b`.

#### Accepts

`.a` is a null-terminated `$noun`.

`.b` is a null-terminated `$noun`.

#### Produces

A `+list`.

#### Source

```hoon
++  weld
  |*  [a=(list) b=(list)]
  =>  .(a ^+((le a) a), b ^+((le b) b))
  =+  42
  |-
  ?~  a  b
  [i=i.a t=$(a t.a)]
```

#### Examples

```
> =b [[2 3] [1 4] ~]

> (weld:nl b [8 9 ~])
[i=[2 3] t=[i=[1 4] t=~[8 9]]]
```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.urbit.org/hoon/stdlib/2m.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
