#2795 List.getSafeRange?

andy Fri 22 May

I'm not sure the semantics -- but its always been cumbersome to manually check ranges. A List.getSafeRange would be nice. Maybe to keep it simple always return null if either start or end is out of bounds?

brian Fri 29 May

I like it, but think the semantics should be to clip which is how we did it in Axon. For example:

"abcd".getSafe(1..10)

clip option would returns "bcd"

null option would return null

The clip option seems more generally useful. Although maybe we call that one clip?

andy Sun 31 May

Eh I think if you passed in an explicit range it needs to "fail" with null. Otherwise you need to check the range anyways so doesn't save you any code.

But I'm not opposed to a "clipSafe" method either. Those are probably both valid use cases.

Login or Signup to reply.