# How to use Combinatorics.jl for permutations

**URL:** <https://discourse.julialang.org/t/how-to-use-combinatorics-jl-for-permutations/90766>\
**Category:** Numerics\
**Tags:** combinatorics\
**Created:** [November 24, 2022, 5:42pm UTC](https://discourse.julialang.org/t/how-to-use-combinatorics-jl-for-permutations/90766 "2022-11-24T17:42:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvenkov1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvenkov1/32/43679_2.png) [@nvenkov1](https://discourse.julialang.org/u/nvenkov1)\
**Post date:** [November 24, 2022, 5:42pm UTC](https://discourse.julialang.org/t/how-to-use-combinatorics-jl-for-permutations/90766/1 "2022-11-24T17:42:33Z")

</div>

I would like to gather all permutations of a certain number of elements of a set. I read that Combinatorics.jl can be used for that. However, I do not know how to use it. I do the following

```julia
using Combinatorics: permutations
p = permutations((-1, 1), 3)

```

and p is of the type Combinatorics.Permutations{Tuple{Int64, Int64}}. How am I supposed to probe this object to get my permutations?

---

<div class="post-metadata">

**Author:** ![nvenkov1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvenkov1/32/43679_2.png) [@nvenkov1](https://discourse.julialang.org/u/nvenkov1)\
**Post date:** [November 24, 2022, 5:49pm UTC](https://discourse.julialang.org/t/how-to-use-combinatorics-jl-for-permutations/90766/2 "2022-11-24T17:49:16Z")

</div>

Okay. You’re supposed to use collect:

```julia
using Combinatorics: permutations
p = permutations((1, 2, 3), 3);
perms = collect(p)

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 24, 2022, 7:43pm UTC](https://discourse.julialang.org/t/how-to-use-combinatorics-jl-for-permutations/90766/3 "2022-11-24T19:43:02Z")

</div>

This will of course depend on what you are trying to do, but generally you’re not supposed to collect them - they are iterators, so you can loop over them without ever materialising the whole thing.
