RG.System.Collections.Generic.One
1.0.1
See the version list below for details.
dotnet add package RG.System.Collections.Generic.One --version 1.0.1
NuGet\Install-Package RG.System.Collections.Generic.One -Version 1.0.1
<PackageReference Include="RG.System.Collections.Generic.One" Version="1.0.1" />
paket add RG.System.Collections.Generic.One --version 1.0.1
#r "nuget: RG.System.Collections.Generic.One, 1.0.1"
// Install RG.System.Collections.Generic.One as a Cake Addin #addin nuget:?package=RG.System.Collections.Generic.One&version=1.0.1 // Install RG.System.Collections.Generic.One as a Cake Tool #tool nuget:?package=RG.System.Collections.Generic.One&version=1.0.1
What is One<T>?
One<T> is a generic collection that contains exactly one item. This kind of generic collection allows you to use LINQ expression to write closures and functional programming.
Installation
Using Package Manager Console
Install-Package RG.System.Collections.Generic.One
Using dotnet CLI
dotnet add package RG.System.Collections.Generic.One
Usage
Include using directive
using System.Collections.Generic;
Create instance of One<T>
// using constructor
var oneInt = new One<int>(1);
// using factory
var oneDecimal = One.Of(100.0m);
// using extension method
var oneString = "Hello World".ToOne();
Use it in LINQ expression as a closure
decimal total = from price in 199m.ToOne()
let quantity = 2m
let subtotal = price * quantity
let tax = subtotal * 0.1m
let discount = 10m
select subtotal + tax - discount;
LINQ Support
When a LINQ expression enumerates from a One<T>, all following features are supported.
Starting a 'closure' LINQ expression
from x in e.ToOne()
Introducing a new range variable
from x in e.ToOne()
let y = 10
Introducing a new range variable from another One<T>
from x in e.ToOne()
from y in one // one is a One<int>, z is an Int32
Returning result
int result = from x in e.ToOne()
let y = x * x
select y;
Multiple awaits
int result = from x in (await GetValue1Async()).ToOne()
join y in (await GetValue2Async()).ToOne() on 1 equals 1
select x * y;
Auto Disposing Range Variables
All disposable range variables are automatically disposed on select.
string ComputeSecretProof(string accessToken) {
string secretProof = from appSecret in Configuration["AppSecret"].ToOne()
let appSecretBytes = Encoding.UTF8.GetBytes(appSecret)
let accessTokenBytes = Encoding.UTF8.GetBytes(accessToken)
let hmacssha256 = new HMACSHA256(appSecretBytes)
let proofBytes = hmacsha256.ComputeHash(accessTokenBytes)
select string.Join("", proofBytes.Select(b => b.ToString("x2")));
// hmacsha256 already disposed at this point
return secretProof;
}
Disabling Auto Dispose
string json = await (Task<string>) from client in httpClient.ToOne(doNotDisposeValueOnDispose: true)
let uri = new Uri(uriString)
let jwtToken = ...
...
select client.GetStringAsync(uri);
// httpClient is not disposed and can still be reused
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RG.System.Collections.Generic.One:
Package | Downloads |
---|---|
RG.Ninja
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.