Skip to content

Commit

Permalink
Bumped funcsharp package to preview.2 (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaliCZ authored Sep 22, 2023
1 parent de2e48c commit 3e23192
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static Try<InvoiceData, IReadOnlyList<Error>> Create(
return Try.Aggregate(
ObjectValidations.NotNull(description),
items.ToList().ToTry(i => i.Any() && i.Count <= 1000, _ => new Error($"{nameof(items)} count must be in range [1, 1000].")),
taxModes.ToTry(t => t.NonEmptyNorNull(), _ => new Error($"{nameof(taxModes)} shouldn't be empty.")),
taxModes.ToTry(t => t.NonEmpty(), _ => new Error($"{nameof(taxModes)} shouldn't be empty.")),
(d, i, t) => new InvoiceData(d, i, totalAmount, t, supportWithheldAmount, tax, transactionDate)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,6 @@ public static bool IsSequential(this IEnumerable<int> source, int startIndex)
return source.Select((value, index) => (value, index)).All(x => x.value == startIndex + x.index);
}

/// <summary>
/// Retuns an empty Enumerable if source is null, otherwise source.
/// </summary>
public static IEnumerable<TSource> OrEmptyIfNull<TSource>(this IEnumerable<TSource> source)
{
if (source == null)
{
return Enumerable.Empty<TSource>();
}

return source;
}

public static bool NonEmptyNorNull<T>(this IEnumerable<T> source)
{
return source is not null && source.Any();
}

public static bool IsEmptyOrNull<T>(this IEnumerable<T> source)
{
return source is null || !source.Any();
}

[Pure]
public static bool NonEmptyNorNull<T>(this IReadOnlyCollection<T> source)
{
return source is not null && source.Count > 0;
}

[Pure]
public static bool IsEmptyOrNull<T>(this IReadOnlyCollection<T> source)
{
Expand All @@ -63,7 +34,9 @@ public static Option<T> SafeFirstOption<T>(this IEnumerable<T> source)
case null:
return Option.Empty<T>();
case IReadOnlyList<T> list:
return list.SafeFirstOption();
return list.Count == 0
? Option.Empty<T>()
: Option.Valued(list[0]);
default:
{
using var enumerator = source.GetEnumerator();
Expand All @@ -73,12 +46,4 @@ public static Option<T> SafeFirstOption<T>(this IEnumerable<T> source)
}
}
}

[Pure]
public static Option<T> SafeFirstOption<T>(this IReadOnlyList<T> list)
{
return list is null || list.Count == 0
? Option.Empty<T>()
: Option.Valued(list[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<Try<InvoiceState, ErrorResult>> GetInvoiceStateAsync(string fi
var url = $"{UniwixBaseUrl}/Invoices/{fileId}";
var result = await GetAsync<List<InvoiceStateResult>>(url);

var validatedResult = result.Where(a => a.NonEmptyNorNull(), _ => ErrorResult.Create($"Invoice {fileId} not found.", ErrorType.InvoiceNotFound));
var validatedResult = result.Where(a => a is not null && a.NonEmpty(), _ => ErrorResult.Create($"Invoice {fileId} not found.", ErrorType.InvoiceNotFound));
return validatedResult.Map(r =>
{
var state = r.OrderByDescending(s => s.Date).First();
Expand Down
2 changes: 1 addition & 1 deletion src/Mews.Fiscalizations.All.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FuncSharp" Version="[8.0.0-preview.1, 9.0)" />
<PackageReference Include="FuncSharp" Version="[8.0.0-preview.2, 9.0)" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Mews.Fiscalizations.All/Mews.Fiscalizations.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/MewsSystems/fiscalizations</RepositoryUrl>
<Icon>https://raw.githubusercontent.com/msigut/eet/master/receipt.png</Icon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>25.0.3</PackageVersion>
<PackageVersion>25.0.4</PackageVersion>
<LangVersion>10</LangVersion>
<ImplicitUsings>true</ImplicitUsings>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
Expand Down

0 comments on commit 3e23192

Please sign in to comment.