diff --git a/eo-runtime/src/main/eo/org/eolang/tuple.eo b/eo-runtime/src/main/eo/org/eolang/tuple.eo index 9ef8d40931..8c38ba3781 100644 --- a/eo-runtime/src/main/eo/org/eolang/tuple.eo +++ b/eo-runtime/src/main/eo/org/eolang/tuple.eo @@ -57,10 +57,16 @@ index.lt 0 index.gte len error "Given index is out of tuple bounds" - if. - index.lt (len.plus -1) - ^.head.at index - ^.tail + at-without-checks index + + # Takes element from the tuple without index validation. + # Here `i` must be an object that can be comparable with `int` using `lt` attribute. + [i] > at-without-checks + i > idx! + if. > @ + idx.lt head.length + ^.^.head.at.at-without-checks idx + ^.^.tail # Create a new tuple with this element added to the end of it. [x] > with diff --git a/eo-runtime/src/test/eo/org/eolang/tuple-tests.eo b/eo-runtime/src/test/eo/org/eolang/tuple-tests.eo index 4172211b44..85dd8fff86 100644 --- a/eo-runtime/src/test/eo/org/eolang/tuple-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/tuple-tests.eo @@ -172,6 +172,24 @@ a.at 0 3 +# Test +[] > at-without-checks-with-first-element + eq. > @ + at-without-checks. + at. + * 100 101 102 + 0 + 100 + +# Test +[] > at-without-checks-with-last-element + eq. > @ + at-without-checks. + at. + * 100 101 102 + 2 + 102 + # Test. [] > tuple-empty-fluent-with-indented-keyword tuple