# Unpacking from a collection

**URL:** <https://discourse.julialang.org/t/unpacking-from-a-collection/84276>\
**Category:** General Usage\
**Created:** [July 15, 2022, 3:15pm UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276 "2022-07-15T15:15:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![uje](https://avatars.discourse-cdn.com/v4/letter/u/5f9b8f/32.png) [@uje](https://discourse.julialang.org/u/uje)\
**Post date:** [July 15, 2022, 3:15pm UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/1 "2022-07-15T15:15:14Z")

</div>

In python I could do this and the result will be as follows

```python
>>> a, b, *c, d = [1, 2, 3, 4, 5, 6]
>>>a
1
>>>b
2
>>>c
[3, 4, 5]
>>>d
6

```

I know there’s unpacking in Julia and know how to use it. But the part where I can pack multiple values into `c` as I did in python here is were I can’t figure out yet.

Have any idea?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 15, 2022, 3:22pm UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/2 "2022-07-15T15:22:18Z")

</div>

[https://github.com/JuliaLang/julia/pull/42902](https://github.com/JuliaLang/julia/pull/42902)

---

<div class="post-metadata">

**Author:** ![uje](https://avatars.discourse-cdn.com/v4/letter/u/5f9b8f/32.png) [@uje](https://discourse.julialang.org/u/uje)\
**Post date:** [July 15, 2022, 6:34pm UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/3 "2022-07-15T18:34:55Z")

</div>

Thank you, can’t wait to have it on board

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 20, 2022, 6:18am UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/4 "2022-07-20T06:18:10Z")

</div>

[here](https://app.slack.com/client/T68168MUP/C67910KEH/thread/C67910KEH-1657898495.843949) a rough workaround.

```julia
julia> macro splatin(e)
           pos=findfirst(el -> !(el isa Symbol), e.args[1].args) 
           L=length(e.args[1].args)
           permute!(e.args[1].args,[1:pos-1...,pos+1:L..., pos])
           R=length(e.args[2].args)
           permute!(e.args[2].args,[1:pos-1...,pos+R-L+1:R..., pos:pos+R-L...])
           return esc(e);
       end    
@splatin (macro with 1 method)

julia> @splatin (a,b, c..., d) = [1,2,3,4,5,6,7];

julia> a,b,c,d
(1, 2, [3, 4, 5, 6], 7)

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [July 20, 2022, 6:25am UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/5 "2022-07-20T06:25:45Z")

</div>

Nice macro, but shouldn’t it be called `@slurp`? Splat is the opposite operation.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 20, 2022, 6:27am UTC](https://discourse.julialang.org/t/unpacking-from-a-collection/84276/6 "2022-07-20T06:27:56Z")

</div>

ok let’s go with @slurpin
