Giter Site home page Giter Site logo

Comments (5)

KristofferC avatar KristofferC commented on June 26, 2024 2

I think it is better to be consistent with other collections here.

from julia.

Seelengrab avatar Seelengrab commented on June 26, 2024

A MethodError would imply that the method doesn't exist - it does exist, but there's nothing to index since the collection is empty. A BoundsError is thus correct.

from julia.

nsajko avatar nsajko commented on June 26, 2024

A MethodError would imply that the method doesn't exist

The idea was that we could turn this into an actual "method not found" situation, something like:

function last(t::Tuple)
    function last_nonempty(t::Tuple{Any,Vararg})
        t[end]
    end
    last_nonempty(t)
end
julia> last((3,))
3

julia> last(())
ERROR: MethodError: no method matching (::var"#last_nonempty#1")(::Tuple{})
The function `last_nonempty` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  (::var"#last_nonempty#1")(::Tuple{Any, Vararg})

from julia.

nsajko avatar nsajko commented on June 26, 2024

Or, a bit more clear:

function last(t::Tuple)
    function throw_if_empty(t::Tuple{Any,Vararg})
        nothing
    end
    throw_if_empty(t)
    t[end]
end

from julia.

KristofferC avatar KristofferC commented on June 26, 2024

The current way is most likely fine the way it is.

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.