# Iterative pair-wise fold

**URL:** <https://discourse.julialang.org/t/iterative-pair-wise-fold/70518>\
**Category:** General Usage\
**Tags:** iterators\
**Created:** [October 27, 2021, 10:00pm UTC](https://discourse.julialang.org/t/iterative-pair-wise-fold/70518 "2021-10-27T22:00:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [October 27, 2021, 10:00pm UTC](https://discourse.julialang.org/t/iterative-pair-wise-fold/70518/1 "2021-10-27T22:00:55Z")

</div>

Is there an iterator or a fold-like function that will take a collection and a function and will apply the function iteratively to neighbour elements pairs until only one element remains? E.g `[1,2,3]` and `/`:

```julia
[1,2,3]
[1/2,2/3] # iteration 1
[3/4] # iteration 2

```

I can probably build something out of `IterTools.partition(x,2,1)` but I am wondering if this is a common enough pattern that someone has already thought of.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [October 27, 2021, 10:15pm UTC](https://discourse.julialang.org/t/iterative-pair-wise-fold/70518/2 "2021-10-27T22:15:36Z")

</div>

look at `? foldl` also `mapfoldl`
