Skip to content

Commit 39fbf8b

Browse files
committed
Update build scripts
1 parent 73424de commit 39fbf8b

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

build.cake

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#load "./build/process.cake"
1616
#load "./build/public-api.cake"
1717
#load "./build/setup-teardown.cake"
18+
#load "./build/utilities.cake"
1819
#load "./build/versioning.cake"
1920
#load "./build/workspace.cake"
2021

build/git.cake

+2-3
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ static (SemanticVersion? Latest, SemanticVersion? LatestStable) GitGetLatestVers
129129
.Where(static x => x.StartsWith("tag: "))
130130
.Select(static x => x.Substring(5))
131131
.Select(static x => {
132-
SemanticVersion? version = null;
133-
var result = SemanticVersion.TryParse(x, out version);
132+
_ = SemanticVersion.TryParse(x, out var version);
134133
return version;
135134
})
136-
.Where(static x => x != null);
135+
.WhereNotNull();
137136

138137
SemanticVersion? latest = null;
139138
SemanticVersion? latestStable = null;

build/utilities.cake

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (C) Tenacom and contributors. Licensed under the MIT license.
2+
// See LICENSE file in the project root for full license information.
3+
4+
#nullable enable
5+
6+
// ---------------------------------------------------------------------------------------------
7+
// Miscellaneous utilities
8+
// ---------------------------------------------------------------------------------------------
9+
10+
using System;
11+
using System.Linq;
12+
13+
/*
14+
* Summary : Filters a sequence of nullable values, taking only those that are not null.
15+
* Type params : T - The type of the elements of this.
16+
* Params : this - An IEnumerable<T> to filter.</param>
17+
* Returns : An IEnumerable<T> that contains elements from the input sequence that are not null.
18+
*/
19+
static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this)
20+
where T : class
21+
{
22+
return @this.Where(IsNotNull) as IEnumerable<T>;
23+
24+
static bool IsNotNull(T? x) => x is not null;
25+
}
26+
27+
/*
28+
* Summary : Filters a sequence of nullable values, taking only those that are not null.
29+
* Type params : T - The type of the elements of this.
30+
* Params : this - An IEnumerable<T> to filter.</param>
31+
* Returns : An IEnumerable<T> that contains elements from the input sequence that are not null.
32+
*/
33+
public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> @this)
34+
where T : struct
35+
{
36+
return @this.Where(IsNotNull).Select(GetValue);
37+
38+
static bool IsNotNull(T? x) => x.HasValue;
39+
40+
static T GetValue(T? x) => x!.Value;
41+
}

0 commit comments

Comments
 (0)