# Converting an array to its elements

**URL:** <https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347>\
**Category:** Help & Support\
**Created:** [June 3, 2021, 7:29pm UTC](https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347 "2021-06-03T19:29:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szabgab](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/szabgab/32/1278_2.png) [@szabgab](https://forum.crystal-lang.org/u/szabgab)\
**Post date:** [June 3, 2021, 7:29pm UTC](https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347/1 "2021-06-03T19:29:44Z")

</div>

```auto
def f(x, y)
    return x + y
end
puts f(2, 3)
values = [3, 4]
puts values
puts f(values) # expected 7

```

The f function expects two parameters. What if I have the values in an array? Can I somehow tell Crystal to pass the content of the array to the function. (In Python this would be done by prefixing variable with a star: f(\*values).

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [June 3, 2021, 7:41pm UTC](https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347/2 "2021-06-03T19:41:02Z")

</div>

Crystal can’t splat arrays at the moment. You basically have two options:

1. Just manually pass args like `f values[0], values[1]`

2. Combine 1 with an `Array` overload

```auto
def f(values : Array)
  f values[0], values[1]
end

f [1, 2]

```

EDIT: For reference: [Splats and tuples - Crystal](https://crystal-lang.org/reference/syntax_and_semantics/splats_and_tuples.html#splatting-a-tuple).

---

<div class="post-metadata">

**Author:** ![jhass](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/jhass/32/1779_2.png) [@jhass](https://forum.crystal-lang.org/u/jhass)\
**Post date:** [June 4, 2021, 8:20am UTC](https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347/3 "2021-06-04T08:20:30Z")

</div>

Option three is `Tuple.from`, useful if your array has mixed types:

```auto
f(*{Int32, Float64}.from(values))

```

---

<div class="post-metadata">

**Author:** ![szabgab](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/szabgab/32/1278_2.png) [@szabgab](https://forum.crystal-lang.org/u/szabgab)\
**Post date:** [June 8, 2021, 5:21pm UTC](https://forum.crystal-lang.org/t/converting-an-array-to-its-elements/3347/4 "2021-06-08T17:21:13Z")

</div>

Thanks for all the replies!
