Last active
August 23, 2019 05:43
-
-
Save NickDarvey/7823941071df3897eb62e5f3ff84ad3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Verifier Combine(params Verifier[] verifiers) => | |
expression => | |
{ | |
var current = Init; | |
foreach (var verify in verifiers) | |
{ | |
var next = verify(expression); | |
current = next.Apply(current.Apply(KeepRight)); | |
} | |
return current; | |
}; | |
public static Verifier Combine2(params Verifier[] verifiers) => | |
expression => from xs in verifiers.TraverseA(v => v(expression)) | |
select Unit.Default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Method | VCount | Mean | Ratio | Gen 0 | Allocated | | |
|--------- |------- |-----------:|------:|-------:|----------:| | |
| Combine | 2 | 163.5 ns | 1.00 | - | - | | |
| Combine2 | 2 | 346.0 ns | 2.63 | 0.2828 | 592 B | | |
| | | | | | | | |
| Combine | 10 | 1,206.3 ns | 1.00 | - | - | | |
| Combine2 | 10 | 2,425.0 ns | 2.03 | 1.0452 | 2192 B | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Combines verifiers | |
/// </summary> | |
/// <remark> | |
/// | Method | VCount | Mean | Ratio | Gen 0 | Allocated | | |
/// |--------------------- |------- |-----------:|------:|-------:|----------:| | |
/// | ThisCombine | 2 | 163.5 ns | 1.00 | - | - | | |
/// | CombineWithTraverseA | 2 | 346.0 ns | 2.63 | 0.2828 | 592 B | | |
/// | | | | | | | | |
/// | ThisCombine | 10 | 1,206.3 ns | 1.00 | - | - | | |
/// | CombineWithTraverseA | 10 | 2,425.0 ns | 2.03 | 1.0452 | 2192 B | | |
/// | |
/// </remark> | |
/// <param name="verifiers">The verifiers to combine.</param> | |
public static Verifier Combine(params Verifier[] verifiers) => | |
expression => | |
{ | |
var current = Init; | |
foreach (var verify in verifiers) | |
{ | |
var next = verify(expression); | |
current = next.Apply(current.Apply(KeepRight)); | |
} | |
return current; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... _combineWithTraverseA = CombineWithTraverseA(sampleVerifiers); | |
/// <summary> | |
/// The combine method using TraverseA. | |
/// </summary> | |
[Benchmark] | |
public Validation<string, Unit> CombineWithTraverseA() | |
{ | |
return _combineWithTraverseA(_expression); | |
} | |
private static Verifier CombineWithTraverseA(params Verifier[] verifiers) => | |
expression => from xs in verifiers.TraverseA(v => v(expression)) | |
select Unit.Default; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment