Add has function to Range and ExclusiveRange.

This commit is contained in:
Dmitry Atamanov
2023-07-19 14:35:29 +05:00
committed by Christoffer Lerno
parent b453186de5
commit 7fbedae604
2 changed files with 28 additions and 12 deletions

View File

@@ -16,6 +16,11 @@ fn usz Range.len(&self) @operator(len)
return (usz)(self.end - self.start + (Type)1);
}
fn bool Range.has(&self, Type value) @inline
{
return value >= self.start && value <= self.end;
}
/**
* @require index < self.len() : "Can't index into an empty range"
**/
@@ -46,6 +51,11 @@ fn usz ExclusiveRange.len(&self) @operator(len)
return (usz)(self.end - self.start);
}
fn bool ExclusiveRange.has(&self, Type value) @inline
{
return value >= self.start && value < self.end;
}
fn void! ExclusiveRange.to_format(&self, Formatter* formatter) @dynamic
{
formatter.printf("[%s..<%s]", self.start, self.end)!;