Skip to content

Commit

Permalink
adressing review:
Browse files Browse the repository at this point in the history
* improve naming
* implement ParseOrNone for IParseable
  • Loading branch information
FreeApophis committed Sep 4, 2023
1 parent 12f3c84 commit c4d790f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Funcky.Extensions;
public static partial class ParseExtensions
{
public static Option<TNumber> ParseGenericNumber<TNumber>(this string value, NumberStyles style, IFormatProvider? provider)
public static Option<TNumber> ParseNumberOrNone<TNumber>(this string value, NumberStyles style, IFormatProvider? provider)
where TNumber : INumberBase<TNumber>
=> TNumber.TryParse(value, style, provider, out var result)
? result
: Option<TNumber>.None;

public static Option<TNumber> ParseGenericNumber<TNumber>(this ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider)
public static Option<TNumber> ParseNumberOrNone<TNumber>(this ReadOnlySpan<char> value, NumberStyles style, IFormatProvider? provider)
where TNumber : INumberBase<TNumber>
=> TNumber.TryParse(value, style, provider, out var result)
? result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ namespace Funcky.Extensions;

public static partial class ParseExtensions
{
public static Option<TParseable> ParseGenericParsable<TParseable>(this ReadOnlySpan<char> value, IFormatProvider? provider)
public static Option<TParseable> ParseOrNone<TParseable>(this ReadOnlySpan<char> value, IFormatProvider? provider)
where TParseable : ISpanParsable<TParseable>
=> TParseable.TryParse(value, provider, out var result)
? result
: Option<TParseable>.None;

public static Option<TParseable> ParseOrNone<TParseable>(this string? value, IFormatProvider? provider)
where TParseable : IParsable<TParseable>
=> TParseable.TryParse(value, provider, out var result)
? result
: Option<TParseable>.None;
}
#endif
7 changes: 4 additions & 3 deletions Funcky/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Funcky.Monads.Result<TValidResult>.InspectError(System.Action<System.Exception!>
Funcky.Monads.Result<TValidResult>.OrElse(Funcky.Monads.Result<TValidResult> fallback) -> Funcky.Monads.Result<TValidResult>
Funcky.Monads.Result<TValidResult>.OrElse(System.Func<System.Exception!, Funcky.Monads.Result<TValidResult>>! fallback) -> Funcky.Monads.Result<TValidResult>
static Funcky.Extensions.EnumeratorExtensions.MoveNextOrNone<T>(this System.Collections.Generic.IEnumerator<T>! enumerator) -> Funcky.Monads.Option<T>
static Funcky.Extensions.ParseExtensions.ParseGenericNumber<TNumber>(this string! value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseGenericNumber<TNumber>(this System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseGenericParsable<TParseable>(this System.ReadOnlySpan<char> value, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>
static Funcky.Extensions.ParseExtensions.ParseNumberOrNone<TNumber>(this string! value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseNumberOrNone<TNumber>(this System.ReadOnlySpan<char> value, System.Globalization.NumberStyles style, System.IFormatProvider? provider) -> Funcky.Monads.Option<TNumber>
static Funcky.Extensions.ParseExtensions.ParseOrNone<TParseable>(this string? value, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>
static Funcky.Extensions.ParseExtensions.ParseOrNone<TParseable>(this System.ReadOnlySpan<char> value, System.IFormatProvider? provider) -> Funcky.Monads.Option<TParseable>

0 comments on commit c4d790f

Please sign in to comment.