Skip to content

Commit 4e31156

Browse files
authored
Merge pull request #47 from I-RzR-I/feature/IndexEnumerable
Feature/index enumerable
2 parents 651c1a8 + 8193c56 commit 4e31156

8 files changed

Lines changed: 581 additions & 3 deletions

File tree

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### **v4.5.0.7408** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 11-02-2026
2+
* [a4fd120] (RzR) -> Auto commit uncommited files
3+
* [bae196d] (RzR) -> Add enumerable method `SelectWithIsLast` and `WithObservable`
4+
15
### **v4.4.0.8476** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 19-01-2026
26
* [0b54e4a] (RzR) -> Add `T` extension methods: `GetPropertyValue`, `GetPropertyStringValue`, `GetPropertyValue`, `ChangePropertyValue`.
37
* [ee95f35] (RzR) -> Add `string` extension methods: `RemoveStartChars`, `RemoveEndChars`.

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,5 +856,78 @@ public static bool HasAny<TSource>(this IEnumerable<TSource> source, Func<TSourc
856856

857857
return false;
858858
}
859+
860+
/// -------------------------------------------------------------------------------------------------
861+
/// <summary>
862+
/// Is last.
863+
/// </summary>
864+
/// <typeparam name="T">Generic type parameter.</typeparam>
865+
/// <param name="source">The source enumerator.</param>
866+
/// <remarks>
867+
/// Using this method, the enumerator will advance.
868+
/// </remarks>
869+
/// <returns>
870+
/// True if last, false if not.
871+
/// </returns>
872+
/// =================================================================================================
873+
public static bool IsLast<T>(this IEnumerator<T> source)
874+
{
875+
if (source.IsNull())
876+
return true;
877+
878+
return source.MoveNext().IsFalse();
879+
}
880+
881+
/// -------------------------------------------------------------------------------------------------
882+
/// <summary>
883+
/// Is last.
884+
/// </summary>
885+
/// <typeparam name="TKey">Type of the key.</typeparam>
886+
/// <typeparam name="TValue">Type of the value.</typeparam>
887+
/// <param name="source">The source enumerator.</param>
888+
/// <remarks>
889+
/// Using this method, the enumerator will advance.
890+
/// </remarks>
891+
/// <returns>
892+
/// True if last, false if not.
893+
/// </returns>
894+
/// =================================================================================================
895+
public static bool IsLast<TKey, TValue>(
896+
this IEnumerator<KeyValuePair<TKey, TValue>> source)
897+
{
898+
if (source.IsNull())
899+
return true;
900+
901+
return source.MoveNext().IsFalse();
902+
}
903+
904+
/// -------------------------------------------------------------------------------------------------
905+
/// <summary>
906+
/// Enumerates select with is last in this collection.
907+
/// </summary>
908+
/// <typeparam name="T">Generic type parameter.</typeparam>
909+
/// <param name="source">The source for this extension method.</param>
910+
/// <returns>
911+
/// An enumerator that allows foreach to be used to process select with is last in this
912+
/// collection.
913+
/// </returns>
914+
/// =================================================================================================
915+
public static IEnumerable<TupleResult<T, bool>> SelectWithIsLast<T>(
916+
this IEnumerable<T> source)
917+
{
918+
using var e = source.GetEnumerator();
919+
if (e.MoveNext().IsFalse())
920+
yield break;
921+
922+
var current = e.Current;
923+
924+
while (e.MoveNext())
925+
{
926+
yield return TupleResult.Create(current, false);
927+
current = e.Current;
928+
}
929+
930+
yield return TupleResult.Create(current, true);
931+
}
859932
}
860933
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// ***********************************************************************
2+
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions
3+
// Author : RzR
4+
// Created On : 2026-01-28 22:01
5+
//
6+
// Last Modified By : RzR
7+
// Last Modified On : 2026-02-11 20:07
8+
// ***********************************************************************
9+
// <copyright file="ObservableEnumeratorExtensions.cs" company="RzR SOFT & TECH">
10+
// Copyright © RzR. All rights reserved.
11+
// </copyright>
12+
//
13+
// <summary>
14+
// </summary>
15+
// ***********************************************************************
16+
17+
#region U S A G E S
18+
19+
using System;
20+
using System.Collections.Generic;
21+
using DomainCommonExtensions.Collections;
22+
using DomainCommonExtensions.Utilities.Ensure;
23+
24+
#endregion
25+
26+
namespace DomainCommonExtensions.ArraysExtensions
27+
{
28+
/// -------------------------------------------------------------------------------------------------
29+
/// <summary>
30+
/// An observable enumerator extensions.
31+
/// </summary>
32+
/// =================================================================================================
33+
public static class ObservableEnumeratorExtensions
34+
{
35+
/// -------------------------------------------------------------------------------------------------
36+
/// <summary>
37+
/// An IEnumerable&lt;T&gt; extension method that convert to observable.
38+
/// </summary>
39+
/// <exception cref="ArgumentNullException">
40+
/// Thrown when one or more required arguments are null.
41+
/// </exception>
42+
/// <typeparam name="T">Generic type parameter.</typeparam>
43+
/// <param name="source">The source to act on.</param>
44+
/// <returns>
45+
/// An ObservableEnumerator&lt;T&gt;
46+
/// </returns>
47+
/// =================================================================================================
48+
public static ObservableEnumerator<T> WithObservable<T>(
49+
this IEnumerable<T> source)
50+
{
51+
DomainEnsure.IsNotNull(source, nameof(source));
52+
53+
return new ObservableEnumerator<T>(source);
54+
}
55+
56+
/// -------------------------------------------------------------------------------------------------
57+
/// <summary>
58+
/// An IEnumerable&lt;T&gt; extension method that convert to observable.
59+
/// </summary>
60+
/// <exception cref="ArgumentNullException">
61+
/// Thrown when one or more required arguments are null.
62+
/// </exception>
63+
/// <typeparam name="T">Generic type parameter.</typeparam>
64+
/// <param name="enumerator">The enumerator to act on.</param>
65+
/// <returns>
66+
/// An ObservableEnumerator&lt;T&gt;
67+
/// </returns>
68+
/// =================================================================================================
69+
public static ObservableEnumerator<T> WithObservable<T>(
70+
this IEnumerator<T> enumerator)
71+
{
72+
DomainEnsure.IsNotNull(enumerator, nameof(enumerator));
73+
74+
return new ObservableEnumerator<T>(enumerator);
75+
}
76+
}
77+
}

src/DomainCommonExtensions/Collections/IndexableEnumerable.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ public IndexableEnumerable(List<T> list)
113113
: this((IList<T>)list)
114114
{ }
115115

116+
/// -------------------------------------------------------------------------------------------------
117+
/// <summary>
118+
/// Initializes a new instance of the <see cref="IndexableEnumerable{T}"/> class.
119+
/// </summary>
120+
/// <param name="list">(Immutable) the list.</param>
121+
/// =================================================================================================
122+
public IndexableEnumerable(IEnumerable<T> list)
123+
: this((IList<T>)list)
124+
{ }
125+
116126
/// -------------------------------------------------------------------------------------------------
117127
/// <summary>
118128
/// Initializes the index enumerable.
@@ -145,6 +155,17 @@ public IndexableEnumerable(List<T> list)
145155
/// </returns>
146156
/// =================================================================================================
147157
public static IIndexableEnumerable<T> Initialize(List<T> list) => new IndexableEnumerable<T>(list);
158+
159+
/// -------------------------------------------------------------------------------------------------
160+
/// <summary>
161+
/// Initializes the index enumerable.
162+
/// </summary>
163+
/// <param name="list">(Immutable) the list.</param>
164+
/// <returns>
165+
/// An IIndexableEnumerable&lt;T&gt;
166+
/// </returns>
167+
/// =================================================================================================
168+
public static IIndexableEnumerable<T> Initialize(IEnumerable<T> list) => new IndexableEnumerable<T>(list);
148169

149170
/// <inheritdoc />
150171
public T this[int index] => _list[index];

0 commit comments

Comments
 (0)