Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uriegel/linqtools
https://github.com/uriegel/linqtools
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/uriegel/linqtools
- Owner: uriegel
- License: mit
- Created: 2023-03-08T21:10:40.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-14T07:39:37.000Z (11 months ago)
- Last Synced: 2024-10-29T21:11:31.387Z (18 days ago)
- Language: C#
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LinqTools
Extensions for LINQ
## Overview
* Extension functions to make Nullable a Monad/Functor
* Extension functions to make Async Function a Monad/Functor
* Ohter Tools usable for fluent syntax## Option< T >
There are Extension Functions for Option to make them Monads/Functors:
* Select
* SelectManyIf you are not sure, if an object is null although the compiler says no, you can create a Nullable from an apparently not Nullable with
```
static T? AsNullable(this T t)```
With the extension functions you can work with Options as if they were the containing type:
```
var res = (from n in teststr
from m in GetFirstStringChecked(n)
where m.Length == 9
from p in ThrowIfNull(m)
select p)
.GetOrDefault("Nothing");
```
As soon as a function returns None, all further processing is skipped.## Result Monad/Functor
There is a Result Monad/Functor, containing either an Ok value or an Error value. You can transform
Results with LINQ queries like:```
var test = from n in await Process.RunAsync("lsblk", "--bytes --output SIZE,NAME,LABEL,MOUNTPOINT,FSTYPE")
let driveLines = n.Split('\n', StringSplitOptions.RemoveEmptyEntries)
let titles = driveLines[0]
let positions = new[]
{
0,
titles.IndexOf("NAME"),
titles.IndexOf("LABEL"),
titles.IndexOf("MOUNT"),
titles.IndexOf("FSTYPE")
}
select driveLines
.Skip(1)
.Select(n => CreateRootItem(n, positions))
.ToArray();
```