diff --git a/core/slice/slice.odin b/core/slice/slice.odin index 5b25c930e..d85756859 100644 --- a/core/slice/slice.odin +++ b/core/slice/slice.odin @@ -486,6 +486,42 @@ repeat :: proc(s: $S/[]$U, count: int, allocator := context.allocator) -> (b: S, return } +// 'unique' replaces consecutive runs of equal elements with a single copy. +// The procedures modifies the slice in-place and returns the modified slice. +@(require_results) +unique :: proc(s: $S/[]$T) -> S #optional_allocator_error where intrinsics.type_is_comparable(T) #no_bounds_check { + if len(s) < 2 { + return s + } + i := 1 + for j in 1.. bool) -> S #optional_allocator_error #no_bounds_check { + if len(s) < 2 { + return s + } + i := 1 + for j in 1.. (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {