Skip to content

Commit

Permalink
feat: Slice from slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Mar 6, 2024
1 parent da0436b commit 348f48b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/slice/slice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class Slice<T> extends Iterable<T> {

Slice.fromList(List<T> list) : this(list, 0, list.length);

Slice.fromSlice(Slice<T> slice, [int start = 0, int end = -1])
: this(slice._list, slice._start + start, end == -1 ? slice._end : slice._start + end);

@override
bool operator ==(Object other) {
return (other is Slice<T> &&
Expand Down
5 changes: 5 additions & 0 deletions lib/src/slice/slice_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ part of 'slice.dart';

extension SliceOnListExtension<T> on List<T> {
Slice<T> asSlice() => Slice.fromList(this);

Slice<T> slice([int start = 0, int? end]) {
end ??= length;
return Slice(this, start, end);
}
}

extension SliceOnSliceIntExtension<T> on Slice<num> {
Expand Down

0 comments on commit 348f48b

Please sign in to comment.