# Custom Compat.jl Block

**URL:** https://discourse.julialang.org/t/custom-compat-jl-block/101328
**Category:** General Usage
**Tags:** compatibility
**Created:** [July 7, 2023, 7:44pm UTC](https://discourse.julialang.org/t/custom-compat-jl-block/101328 "2023-07-07T19:44:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)
#### Post date: [July 7, 2023, 7:44pm UTC](https://discourse.julialang.org/t/custom-compat-jl-block/101328/1 "2023-07-07T19:44:10Z")

</div>

I wrote a function to collect an iterator into a tuple:

```julia
collect_tuple(itr) = _collect_tuple(Iterators.peel(itr))
_collect_tuple(peel_return) = _collect_tuple(peel_return...)
_collect_tuple(::Nothing) = ()
_collect_tuple(val, rest::Iterators.Rest) = (val, collect_tuple(rest)...)

```

It works in Julia 1.9, but fails in 1.6 because, instead of returning `nothing`, calling `Iterators.peel` on an empty container fails on a `BoundsError`. I’d like to maintain LTS compatibility, so I’m trying to come up with a way to handle this change.

I first looked at `Compat.jl`, but this case isn’t an included function. Another option would be to add a `try..catch` and check for a `BoundsError`. I can easily leave this in all versions since this isn’t a hot part of the code, but on principle, I’d love to drop the error check for Julia versions that don’t need it.

Is there anything like

```julia
@compat begin

:default begin
    some code...
end
v"1.6" begin
   slightly different code...
end

end

```

that I can do?

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 7, 2023, 8:15pm UTC](https://discourse.julialang.org/t/custom-compat-jl-block/101328/2 "2023-07-07T20:15:02Z")

</div>

```julia
@static if VERSION ≥ v"1.9"
   # do new Julia stuff here
else
    # do pre-Julia 1.9 stuff
end

```

```julia
julia> VERSION
v"1.9.0"

julia> VERSION ≥ v"1.9"
true

```
