Skip to content

Commit 2cdcf86

Browse files
authored
Version 1.2.1 (#7)
Version 1.2.1
1 parent f8d5f54 commit 2cdcf86

File tree

9 files changed

+122
-60
lines changed

9 files changed

+122
-60
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ tab_width = 4
112112
indent_size = 4
113113
end_of_line = crlf
114114
dotnet_style_allow_multiple_blank_lines_experimental = false:suggestion
115+
dotnet_style_prefer_collection_expression = false
116+
csharp_style_prefer_primary_constructors = false
115117
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
116118
dotnet_style_explicit_tuple_names = true:suggestion
117119
dotnet_style_prefer_inferred_tuple_names = true:suggestion

.github/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The following **Extension Methods** are contained:
4141
- `(ReadOnly-)Span<T>.Take(int count)`
4242
- `(ReadOnly-)Span<T>.SkipLast(int count)`
4343
- `(ReadOnly-)Span<T>.Takelast(int count)`
44+
- `(ReadOnly-)Span<T>.SkipWhile(Predicate<T> condition)`
45+
- `(ReadOnly-)Span<T>.TakeWhile(Predicate<T> condition)`
4446

4547
## Contributing
4648

Changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.1] - 2024-1-25
9+
10+
### Fixed
11+
12+
- Ambiguous Extension Methods (https://github.com/draconware-dev/SpanExtensions.Net/issues/6)
13+
- Correctness of some documentation comments
14+
15+
### Changed
16+
17+
- moved custom Enumerators into `SpanExtensions.Enumerators`
18+
- declared every `GetEnumerator` method in a ref struct as `readonly`
19+
820
## [1.2.0] - 2023-12-28
921

1022
### Added

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 draconware-dev
3+
Copyright (c) 2024 draconware-dev
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/Enumerators/Split/SpanSplitEnumerator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32

43
namespace SpanExtensions.Enumerators
54
{

src/Extensions/Span/SpanExtensions.Linq.cs

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,51 @@ public static Span<T> Take<T>(this Span<T> source, int count)
220220
{
221221
return source[..count];
222222
}
223+
/// <summary>
224+
/// Bypasses elements in <paramref name="source"/> as long as a <paramref name="condition"/> is true and then returns the remaining elements. The element's index is used in the logic of the predicate function.
225+
/// </summary>
226+
/// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
227+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
228+
/// <param name="condition">A function to test each element for a condition.</param>
229+
/// <returns>A <see cref="ReadOnlySpan{T}"/> that contains the elements from <paramref name="source"/> starting at the first element in the linear series that does not pass the specified <paramref name="condition" />.</returns>
230+
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="condition"/> is null.</exception>
231+
public static Span<T> SkipWhile<T>(this Span<T> source, Predicate<T> condition)
232+
{
233+
int count = 0;
234+
while(count < source.Length)
235+
{
236+
T t = source[count];
237+
if(!condition(t))
238+
{
239+
return source.Skip(count);
240+
}
241+
count++;
242+
}
243+
return Span<T>.Empty;
244+
}
245+
246+
/// <summary>
247+
/// Returns elements from <paramref name="source"/> as long as a specified <paramref name="condition"/> is true, and then skips the remaining elements.
248+
/// </summary>
249+
/// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
250+
/// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
251+
/// <param name="condition">A function to test each element for a condition.</param>
252+
/// <returns>A <see cref="ReadOnlySpan{T}"/> that contains elements from <paramref name="source"/> that occur before the element at which the <paramref name="condition"/> no longer passes.</returns>
253+
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="condition"/> is null.</exception>
254+
public static Span<T> TakeWhile<T>(this Span<T> source, Predicate<T> condition)
255+
{
256+
int count = 0;
257+
while(count < source.Length)
258+
{
259+
T t = source[count];
260+
if(!condition(t))
261+
{
262+
return source.Take(count);
263+
}
264+
count++;
265+
}
266+
return Span<T>.Empty;
267+
}
223268

224269
/// <summary>
225270
/// Returns a new <see cref="Span{T}"/> that contains the elements from source with the last <paramref name="count"/> elements of the source collection omitted.
@@ -287,7 +332,7 @@ public static Half Average(this Span<Half> source)
287332
/// <summary>
288333
/// Computes the Average of all the values in <paramref name="source"/>.
289334
/// </summary>
290-
/// <param name="source">The <see cref="ReadOnlySpan{Byte}"/> to operate on.</param>
335+
/// <param name="source">The <see cref="Span{Byte}"/> to operate on.</param>
291336
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
292337
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
293338
public static byte Average(this Span<byte> source)
@@ -298,7 +343,7 @@ public static byte Average(this Span<byte> source)
298343
/// <summary>
299344
/// Computes the Average of all the values in <paramref name="source"/>.
300345
/// </summary>
301-
/// <param name="source">The <see cref="ReadOnlySpan{UInt16}"/> to operate on.</param>
346+
/// <param name="source">The <see cref="Span{UInt16}"/> to operate on.</param>
302347
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
303348
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
304349
public static ushort Average(this Span<ushort> source)
@@ -309,7 +354,7 @@ public static ushort Average(this Span<ushort> source)
309354
/// <summary>
310355
/// Computes the Average of all the values in <paramref name="source"/>.
311356
/// </summary>
312-
/// <param name="source">The <see cref="ReadOnlySpan{uint32}"/> to operate on.</param>
357+
/// <param name="source">The <see cref="Span{uint32}"/> to operate on.</param>
313358
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
314359
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
315360
public static uint Average(this Span<uint> source)
@@ -319,7 +364,7 @@ public static uint Average(this Span<uint> source)
319364
/// <summary>
320365
/// Computes the Average of all the values in <paramref name="source"/>.
321366
/// </summary>
322-
/// <param name="source">The <see cref="ReadOnlySpan{UInt64}"/> to operate on.</param>
367+
/// <param name="source">The <see cref="Span{UInt64}"/> to operate on.</param>
323368
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
324369
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
325370
public static ulong Average(this Span<ulong> source)
@@ -330,7 +375,7 @@ public static ulong Average(this Span<ulong> source)
330375
/// <summary>
331376
/// Computes the Average of all the values in <paramref name="source"/>.
332377
/// </summary>
333-
/// <param name="source">The <see cref="ReadOnlySpan{SByte}"/> to operate on.</param>
378+
/// <param name="source">The <see cref="Span{SByte}"/> to operate on.</param>
334379
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
335380
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
336381
public static sbyte Average(this Span<sbyte> source)
@@ -341,7 +386,7 @@ public static sbyte Average(this Span<sbyte> source)
341386
/// <summary>
342387
/// Computes the Average of all the values in <paramref name="source"/>.
343388
/// </summary>
344-
/// <param name="source">The <see cref="ReadOnlySpan{Int16}"/> to operate on.</param>
389+
/// <param name="source">The <see cref="Span{Int16}"/> to operate on.</param>
345390
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
346391
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
347392
public static short Average(this Span<short> source)
@@ -352,7 +397,7 @@ public static short Average(this Span<short> source)
352397
/// <summary>
353398
/// Computes the Average of all the values in <paramref name="source"/>.
354399
/// </summary>
355-
/// <param name="source">The <see cref="ReadOnlySpan{Int32}"/> to operate on.</param>
400+
/// <param name="source">The <see cref="Span{Int32}"/> to operate on.</param>
356401
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
357402
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
358403
public static int Average(this Span<int> source)
@@ -363,7 +408,7 @@ public static int Average(this Span<int> source)
363408
/// <summary>
364409
/// Computes the Average of all the values in <paramref name="source"/>.
365410
/// </summary>
366-
/// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
411+
/// <param name="source">The <see cref="Span{Int64}"/> to operate on.</param>
367412
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
368413
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
369414
public static long Average(this Span<long> source)
@@ -374,7 +419,7 @@ public static long Average(this Span<long> source)
374419
/// <summary>
375420
/// Computes the Average of all the values in <paramref name="source"/>.
376421
/// </summary>
377-
/// <param name="source">The <see cref="ReadOnlySpan{Single}"/> to operate on.</param>
422+
/// <param name="source">The <see cref="Span{Single}"/> to operate on.</param>
378423
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
379424
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
380425
public static float Average(this Span<float> source)
@@ -385,7 +430,7 @@ public static float Average(this Span<float> source)
385430
/// <summary>
386431
/// Computes the Average of all the values in <paramref name="source"/>.
387432
/// </summary>
388-
/// <param name="source">The <see cref="ReadOnlySpan{Double}"/> to operate on.</param>
433+
/// <param name="source">The <see cref="Span{Double}"/> to operate on.</param>
389434
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
390435
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
391436
public static double Average(this Span<double> source)
@@ -396,7 +441,7 @@ public static double Average(this Span<double> source)
396441
/// <summary>
397442
/// Computes the Average of all the values in <paramref name="source"/>.
398443
/// </summary>
399-
/// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
444+
/// <param name="source">The <see cref="Span{Decimal}"/> to operate on.</param>
400445
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
401446
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
402447
public static decimal Average(this Span<decimal> source)
@@ -407,7 +452,7 @@ public static decimal Average(this Span<decimal> source)
407452
/// <summary>
408453
/// Computes the Average of all the values in <paramref name="source"/>.
409454
/// </summary>
410-
/// <param name="source">The <see cref="ReadOnlySpan{BigInteger}"/> to operate on.</param>
455+
/// <param name="source">The <see cref="Span{BigInteger}"/> to operate on.</param>
411456
/// <returns>The Average of all the values in <paramref name="source"/>.</returns>
412457
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
413458
public static BigInteger Average(this Span<BigInteger> source)

0 commit comments

Comments
 (0)