# \[Idea\] Splat def parameters into array

**URL:** <https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898>\
**Category:** Offtopic\
**Created:** [April 20, 2026, 1:55pm UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898 "2026-04-20T13:55:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [April 20, 2026, 1:55pm UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898/1 "2026-04-20T13:55:03Z")

</div>

Splat parameters are currently moved into a tuple.

```cr
def foo(*x)
  x
end

typeof(foo(1, true)) # => Tuple(Int32, Bool)

```

It would be nice if splatting could support other collection types, including dynamically sized ones. This is not useful for forwarding parameters, one of the primary purposes of splat tuples.  
But it is convenient for a neat syntax where the def defines the collection type and the caller doesn’t have to worry about which type to chose. The def can own it which could enable performance optimizations.

A use case for that is the new process spawn API from [RFC 25](https://github.com/crystal-lang/rfcs/pull/25).

> <https://github.com/crystal-lang/rfcs/pull/25/files/f20a303d5b791594e9e3f887991cb73ca412dfc5#diff-dca57e74cdd72bd324cf7ad70468e8693594906031f1e0fbb3b88278e0d8351f>
>
> \*\*Preview\*\*: https://github.com/crystal-lang/rfcs/blob/rfc/process-spawn-api/tex…t/0025-process-spawn-api.md

Example:

```cr
def foo(*x : *Array(Bool | Int32))
  x
end

typeof(foo(1, true)) # => Array(Bool | Int32)

```

The call `foo(1, true)` would expand to an implicit array-like literal, equivalent to `foo(Array(Bool | Int32){1, true})`.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [May 12, 2026, 10:09am UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898/2 "2026-05-12T10:09:10Z")

</div>

12 posts were split to a new topic: [Splatting in `#values_at`](https://forum.crystal-lang.org/t/splatting-in-values-at/8938)

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [May 12, 2026, 10:17am UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898/3 "2026-05-12T10:17:24Z")

</div>

I extracted the thread about `#values_at` into [Splatting in `#values_at`](https://forum.crystal-lang.org/t/splatting-in-values-at/8938) because it’s not directly related to array splatting.

The key point for this discussion:

Splat parameters should be able to receive splat arguments (and forward them):

```auto
def foo(*x : *Array(Bool | Int32))
  x
end

tuple = {1, true}
foo(*tuple) # this call must create a new array from the tuple

ary = [1, true]
foo(*ary) # this call should pass `ary` and not create a new array

```

Question is how this should work if the types to not match exactly? (e.g. if the argument is `Array(Int32)`?

---

<div class="post-metadata">

**Author:** ![Carlos](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@Carlos](https://forum.crystal-lang.org/u/Carlos)\
**Post date:** [May 12, 2026, 11:52am UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898/4 "2026-05-12T11:52:19Z")

</div>

But this is to be restricted to a limited number of builtin types? Or how would the compiler know how to create and populate instances of user defined collection types?

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [May 12, 2026, 1:27pm UTC](https://forum.crystal-lang.org/t/idea-splat-def-parameters-into-array/8898/5 "2026-05-12T13:27:15Z")

</div>

For example, the compiler would rewrite these arguments:

```auto
foo(1, true)

```

to create an [array-like literal](https://crystal-lang.org/reference/1.20/syntax_and_semantics/literals/array.html#array-like-type-literal) and pass that instead.

```auto
foo(Array(Bool | Int32){1, true})

```

Which then further expands to something like this:

```auto
%temp = Array(Bool | Int32).new
%temp << 1
%temp << true
foo(%temp)

```

So custom types are supported as long as they support array-like literal construction.
