See Getting the last element of an iterator for a previous discussion.
See also https://github.com/JuliaLang/julia/pull/37648