# COMPOSE of TUPLE! and PATH! (and toplevel GROUP!)

**URL:** <https://revolt.metaeducation.com/forum/t/compose-of-tuple-and-path-and-toplevel-group/2056>\
**Category:** Feature Discover\
**Created:** [October 19, 2023, 6:39am UTC](https://revolt.metaeducation.com/forum/t/compose-of-tuple-and-path-and-toplevel-group/2056 "2023-10-19T06:39:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hostilefork](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/hostilefork/32/421_2.png) [@hostilefork](https://revolt.metaeducation.com/forum/u/hostilefork)\
**Post date:** [October 19, 2023, 6:39am UTC](https://revolt.metaeducation.com/forum/t/compose-of-tuple-and-path-and-toplevel-group/2056/1 "2023-10-19T06:39:14Z")

</div>

While working on @BlackATTR's query, I noticed code that was making paths (now tuples) out of components via TO TUPLE! COMPOSE of a BLOCK!. Like this:

```
to tuple! compose [obj clauses (kwd.1)]

```

But did you know that COMPOSE can act directly on TUPLE! and PATH! You could instead just write:

```
compose $obj.clauses.(kwd.1)

```

It supports splices as well:

```
>> compose $(10 + 20)/a/b/(spread [c d e])/(reverse [g f])
== 30/a/b/c/d/e/[f g]

```

And if you remember that TUPLE! can be nested underneath PATH! (not vice versa) then you can COMPOSE/DEEP and handle mixed tuples and paths:

```
>> compose/deep $(10 + 20)/a/b.(spread [c d e])
== 30/a/b.c.d.e

```

Voids can vanish...so there can be fewer dots in an output tuple than in the input:

```
>> compose $a.(when 1 = 0 [b]).c
== a.c

```

Empty splices will vanish as well:

```
>> compose $a.(spread []).c
== a.c

```

You can't compose in NULLs as an important safety measure...central to the design!

```
>> compose $a.(select [x 10 y 20] 'b).c
** Script Error: non-NULL value required (see OPT, TRY, REIFY)
**Near: [a** (select [x 10 y 20] 'b) c]

```

But don't forget about OPT as the way to convert nulls to void when that's what you meant!

```
>> compose $a.(opt select [x 10 y 20] 'b).c
== a.c

```

## You can also COMPOSE a GROUP!

In R3-Alpha, only BLOCK! would compose. Everything else was passed-through as-is, including GROUP!s (PAREN!s in their terminology)

```
r3-alpha>> compose quote (1 + (2 + 3)) ; R3-alpha QUOTE (modern THE)
== (1 + (2 + 3))

```

Red just doesn't allow it:

```
red>> compose quote (1 + (2 + 3)) ; Red QUOTE (modern THE)
*** Script Error: compose does not allow paren! for its value argument

```

So you'd wind up having to make BLOCK!s and then convert them:

```
red>> as paren! compose [1 + (2 + 3)]
== (1 + 5)

```

But in Revolt, group composing works... it just leaves the top group as-is.

```
>> compose $(1 + (2 + 3))
== (1 + 5)

```

---

<div class="post-metadata">

**Author:** ![hostilefork](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/hostilefork/32/421_2.png) [@hostilefork](https://revolt.metaeducation.com/forum/u/hostilefork)\
**Post date:** [October 1, 2024, 2:02pm UTC](https://revolt.metaeducation.com/forum/t/compose-of-tuple-and-path-and-toplevel-group/2056/3 "2024-10-01T14:02:33Z")

</div>

With changes to things like SET-GROUP [becoming a CHAIN!](https://revolt.metaeducation.com/forum/t/introducingnew-chain-datatype/2226), we now have a situation where we are getting this behavior:

```
>> var: $x

>> compose [(var): 10]
== [(var): 10] ; hm, no substitution?

```

So this would see the **`(var): 10`** as a subsequence and require **`:DEEP`**.

_But I don't think DEEP should be necessary for this._ So I imagine that sequences are considered to be part of the same level for the purposes of COMPOSE'ing.

> [@hostilefork](#):
>
> And if you remember that TUPLE! can be nested underneath PATH! (not vice versa) then you can COMPOSE/DEEP and handle mixed tuples and paths:
> 
> ```plaintext
> >> compose/deep $(10 + 20)/a/b.(spread [c d e])
> == 30/a/b.c.d.e
> 
> ```

By that rule, I would imagine this would not require DEEP either.
