dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Slice method in RefEnumerable<T> and ReadOnlyRefEnumerable<T>

Open risinghero opened this issue 1 year ago • 2 comments

Overview

Slice method in RefEnumerable<T> and ReadOnlyRefEnumerable<T> analogue to Slice method of Span.

API breakdown

namespace CommunityToolkit.SomePackage;

public class ReadOnlyRefEnumerable<T>
{
    public ReadOnlyRefEnumerable<T> Slice(int start,int length);
}

Usage example

var span=new Span2D<double>(5,5);//matrix representation
span.GetColumn(0)[..3];//get 3 values from matrix

### Breaking change?

No

### Alternatives

Alternative is to copy everything to span.

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item

risinghero avatar Jan 07 '25 14:01 risinghero

Is this not the same as span[.., ..3].GetColumn(0)? 🤔

Sergio0694 avatar Jan 07 '25 14:01 Sergio0694

Looks like it is a solution. Though Slice for my purpose will be better and it feels like natural method analogue to span<T> slice or Array<T> slice.

risinghero avatar Jan 07 '25 15:01 risinghero