You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I love FluentAssertions and use it for F#. However, F#'s overload resolution and type inference means that some parts of FluentAssertions are more difficult or verbose to use than with C#.
One thing that is annoying is that I want to be able to do this (note that I'm ignoring the because limitation mentioned in #2225 to make this point more clear):
elements.Should().AllSatisfy(fun e -> e.Should.Be(expected))
This fails to compile because AllSatisfy takes an Action, which means there must be no return value. But e.Should.Be(expected) returns a value of type AndConstraint<...Assertions>, and therefore compilation fails.
The ad-hoc, verbose workaround is to insert |> ignore in these places:
elements.Should().AllSatisfy(fun e -> e.Should.Be(expected)|> ignore)
The above compiles. But I have verified that if I add an extension like the below, the first example also compiles:
typeGenericCollectionAssertions<'T>withmemberthis.AllSatisfy(expected:Func<'T,'TIgnored>)=
this.AllSatisfy(fun x -> expected.Invoke(x)|> ignore)
My proposal is to change all relevant Action<T>-based overloads to instead use Func<T, TIgnored>, so that the "clean" F# code will compile as is. (Alternatively, new overloads could be added alongside existing ones.)
Alternative Concerns
No response
The text was updated successfully, but these errors were encountered:
For what it's worth, I am no longer interested in this. As detailed in #2225 (comment), I am creating a brand new F# assertions library inspired by FluentAssertions. Feel free to close.
Background and motivation
I love FluentAssertions and use it for F#. However, F#'s overload resolution and type inference means that some parts of FluentAssertions are more difficult or verbose to use than with C#.
One thing that is annoying is that I want to be able to do this (note that I'm ignoring the
because
limitation mentioned in #2225 to make this point more clear):This fails to compile because
AllSatisfy
takes anAction
, which means there must be no return value. Bute.Should.Be(expected)
returns a value of typeAndConstraint<...Assertions>
, and therefore compilation fails.The ad-hoc, verbose workaround is to insert
|> ignore
in these places:The above compiles. But I have verified that if I add an extension like the below, the first example also compiles:
My proposal is to change all relevant
Action<T>
-based overloads to instead useFunc<T, TIgnored>
, so that the "clean" F# code will compile as is. (Alternatively, new overloads could be added alongside existing ones.)Alternative Concerns
No response
The text was updated successfully, but these errors were encountered: