e

    elect

    1 month ago
    I'd like to check if a range is within another range, ie
    i-2..i+2 in wd.indices
    e

    ephemient

    1 month ago
    there's two possible answers, both reasonable for different purposes:
    this.start <= other.endInclusive && this.endInclusive >= other.start
    this.start >= other.start && this.endInclusive <= other.endInclusive
    plus additional considerations around what the result should be with empty ranges
    e

    elect

    1 month ago
    I don't see any reason why one would interpret this as the first option
    r

    Ruckus

    1 month ago
    I - 2 in wd.indices && I + 2 in wd.indices
    e

    elect

    1 month ago
    I'm doing exactly this atm
    l

    lhwdev

    1 month ago
    Thinking how operator
    in
    is implemented in Kotlin, it seems to imply that some element is contained in some set(collection), not subset. In java, there is
    containsAll
    , not
    contains
    .
    Klitos Kyriacou

    Klitos Kyriacou

    1 month ago
    This would work but would currently be too expensive:
    wd.indices.toSet().containsAll((i-2..i+2).toSet())
    That's only because toSet() creates a LinkedHashSet. Perhaps it could be optimized to create a specialized Set that just keeps the range as its only property and whose
    contains
    method just forwards to the range, and defines a suitably specialized
    containsAll
    . Then the above code would have good performance. Or perhaps just a new
    containsAll
    method on ranges.
    l

    lhwdev

    1 month ago
    Yes, sorry for not being clear. I meant
    contains
    (which corresponds to
    in
    ) does not work for set-to-set. (like
    Set.contains(Set)
    )