https://github.com/skyl1te/recreating-default-methods-where-first-etc
The project is a C# library that extends the functionality of `IEnumerable<T>` with custom extension methods.
https://github.com/skyl1te/recreating-default-methods-where-first-etc
csharp extension-methods ienumerator net-7-0
Last synced: 9 months ago
JSON representation
The project is a C# library that extends the functionality of `IEnumerable<T>` with custom extension methods.
- Host: GitHub
- URL: https://github.com/skyl1te/recreating-default-methods-where-first-etc
- Owner: Skyl1te
- License: mit
- Created: 2024-06-26T10:28:45.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-26T10:31:57.000Z (about 2 years ago)
- Last Synced: 2025-03-14T07:41:32.754Z (over 1 year ago)
- Topics: csharp, extension-methods, ienumerator, net-7-0
- Language: C#
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Yield_Return
## Overview
The `Yield_Return` project is a C# library that extends the functionality of `IEnumerable` with custom extension methods. This project demonstrates how to create and use these methods, including implementations of common LINQ operations such as `Where`, `First`, `Any`, `All`, `Count`, and others using the `yield return` statement for deferred execution.
## Features
- **Print**: Prints the elements of a collection to the console.
- **MyCount**: Returns the number of elements in a collection.
- **MyWhere**: Filters elements of a collection based on a predicate.
- **MyFirst**: Returns the first element in a collection that satisfies a specified condition.
- **MyAny**: Checks if any element in a collection satisfies a specified condition.
- **MyAll**: Checks if all elements in a collection satisfy a specified condition.
- **MyCountOf**: Returns the number of elements in a collection that satisfy a specified condition.
- **MyLast**: Returns the last element in a collection that satisfies a specified condition.
## Getting Started
### Prerequisites
- .NET SDK
### Installation
Clone the repository:
```bash
git clone https://github.com/yourusername/Yield_Return.git
cd Yield_Return
```
### Usage
Create a new C# project or open an existing one. Add a reference to the `Yield_Return` library.
Here is an example demonstrating how to use the custom extension methods:
```csharp
using System;
using System.Collections.Generic;
using Yield_Return;
namespace Example
{
class Program
{
static void Main(string[] args)
{
string[] words = { "adsad", "sdasdsa", "qqqqe" };
Console.WriteLine(words.MyCount());
Console.WriteLine("----------------");
int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
foreach (int num in nums.MyWhere(i => i % 2 == 0))
{
Console.WriteLine(num);
}
Console.WriteLine("----------------");
Console.WriteLine(nums.MyFirst(i => i % 2 == 0));
Console.WriteLine("----------------");
Console.WriteLine(nums.MyCountOf(i => i % 2 == 0));
Console.WriteLine("----------------");
Console.WriteLine(nums.MyLast(i => i % 2 == 0));
}
}
}
```
### Methods
#### `Print(this IEnumerable collection)`
Prints the elements of the collection to the console.
```csharp
public static void Print(this IEnumerable collection)
```
#### `MyCount(this IEnumerable collection)`
Returns the number of elements in the collection.
```csharp
public static int MyCount(this IEnumerable collection)
```
#### `MyWhere(this IEnumerable collection, Func func)`
Filters elements of the collection based on a predicate.
```csharp
public static IEnumerable MyWhere(this IEnumerable collection, Func func)
```
#### `MyFirst(this IEnumerable collection, Func func)`
Returns the first element in the collection that satisfies a specified condition.
```csharp
public static T MyFirst(this IEnumerable collection, Func func)
```
#### `MyAny(this IEnumerable collection, Func func)`
Checks if any element in the collection satisfies a specified condition.
```csharp
public static bool MyAny(this IEnumerable collection, Func func)
```
#### `MyAll(this IEnumerable collection, Func func)`
Checks if all elements in the collection satisfy a specified condition.
```csharp
public static bool MyAll(this IEnumerable collection, Func func)
```
#### `MyCountOf(this IEnumerable collection, Func func)`
Returns the number of elements in the collection that satisfy a specified condition.
```csharp
public static int MyCountOf(this IEnumerable collection, Func func)
```
#### `MyLast(this IEnumerable collection, Func func)`
Returns the last element in the collection that satisfies a specified condition.
```csharp
public static T MyLast(this IEnumerable collection, Func func)
```
## Contributing
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.