Skip to content

Commit

Permalink
Merge pull request #56 from BoBoBaSs84/docs/improve-documentation
Browse files Browse the repository at this point in the history
chore(docs): improved documentation
  • Loading branch information
BoBoBaSs84 authored Nov 12, 2023
2 parents 6e03a2f + c57449a commit 247480f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<VersionMajor>1</VersionMajor>
<VersionMinor>7</VersionMinor>
<VersionPatch>1</VersionPatch>
<VersionPatch>2</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
<VersionSuffix Condition="$(Configuration.Equals('Debug'))">Development</VersionSuffix>
</PropertyGroup>
Expand Down
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,47 @@
[![CodeQL](https://github.com/BoBoBaSs84/BB84.Extensions/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/BoBoBaSs84/BB84.Extensions/actions/workflows/codeql.yml)
[![Issues](https://img.shields.io/github/issues/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions/issues)
[![Commit](https://img.shields.io/github/last-commit/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions/commit/main)
[![Forks](https://img.shields.io/github/forks/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions/network)
[![Size](https://img.shields.io/github/repo-size/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions)
[![stars](https://img.shields.io/github/stars/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions/stargazers)
[![License](https://img.shields.io/github/license/BoBoBaSs84/BB84.Extensions)](https://github.com/BoBoBaSs84/BB84.Extensions/blob/main/LICENSE)
[![NuGet](https://img.shields.io/nuget/v/BB84.Extensions.svg?logo=nuget&logoColor=white)](https://www.nuget.org/packages/BB84.Extensions)

# BB84.Extensions

A collection of some random C# extensions I needed in many projects.

## Usage

Depending on the application, there are several ways to skin a cat.

### Example extensions

#### Start of week

The `StartOfWeek` method returns the first day of the week using the specified date and the definition of the first day of the week.

```csharp
DateTime today = new(2023, 9, 5);
DateTime startOfWeek = today.StartOfWeek();
```

#### Random choice

The `RandomChoice` method returns a randomly chosen item from a given array.

```csharp
int[] ints = { 1, 2, 3 };
int i = ints.RandomChoice();
```

#### For each

The `ForEach` method iterates over an enumerable and executes an action on each element.

```csharp
int hits = default;
IEnumerable<string> strings = new List<string>() { "a", "ab", "b", "bb" };
strings.ForEach(x => x.Contains("a"), x => hits++);
```

## Documentation

The complete API documentation can be found [here](https://bobobass84.github.io/BB84.Extensions/).
8 changes: 4 additions & 4 deletions src/BB84.Extensions/EnumerableExtensions.ForEach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
public static partial class EnumerableExtensions
{
/// <summary>
/// Iterates over an enumerable and executes an Action on each element.
/// Iterates over an enumerable and executes an action on each element.
/// </summary>
/// <typeparam name="T">The type of the elements of source.</typeparam>
/// <param name="items">A sequence of values to invoke an action on.</param>
/// <param name="action">An Action to invoke on each source element.</param>
/// <param name="action">The action to invoke on each source element.</param>
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
foreach (T item in items)
action(item);
}

/// <summary>
/// Iterates over an enumerable and executes an Action on each element.
/// Iterates over an enumerable and executes an action on each element.
/// </summary>
/// <typeparam name="T">The type of the elements of source.</typeparam>
/// <param name="items">A sequence of values to invoke an action on.</param>
/// <param name="predicate">The function to test each element for a condition.</param>
/// <param name="action">An Action to invoke on each source element.</param>
/// <param name="action">The action to invoke on each source element.</param>
public static void ForEach<T>(this IEnumerable<T> items, Func<T, bool> predicate, Action<T> action)
{
foreach (T item in items.Where(predicate))
Expand Down

0 comments on commit 247480f

Please # to comment.