Skip to content

Commit

Permalink
Minor LINQ improvements (#220)
Browse files Browse the repository at this point in the history
* Test LINQ on Gen

* Support LINQ Select for Range

* Housekeeping

Co-authored-by: Nikos Baxevanis <[email protected]>
  • Loading branch information
mausch and moodmosaic authored Oct 3, 2020
1 parent b1906bb commit 6c22e89
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Hedgehog/LinqSupport.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ module PropertyLinqSupport =
let bind2Unit (pa : Property<'a>) (f : Func<'a, Property<'b>>) (proj : Action<'a, 'b>) : Property<unit> =
Property.bind pa (fun a ->
Property.bind (f.Invoke a) (fun b -> Property.fromThrowing proj.Invoke (a, b)))

[<Extension>]
module RangeLinqSupport =

[<Extension>]
[<CompiledName("Select")>]
let select (r : Range<'a>) (f : Func<'a, 'b>) : Range<'b> =
Range.map (fun x -> f.Invoke x) r
34 changes: 34 additions & 0 deletions tests/Hedgehog.CSharp.Tests/LinqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,39 @@ from i in ForAll(Gen.Int32(Range.Constant(1, 10)))
from j in ForAll(Gen.Int32(Range.Constant(1, i)))
select j <= i);
}

[Fact]
public void CanUseSelectWithGen()
{
Gen<bool> a =
from i in Gen.Bool
select !i;
}

[Fact]
public void CanUseWhereWithGen()
{
Gen<bool> a =
from i in Gen.Bool
where i
select !i;
}

[Fact]
public void CanUseSelectManyWithGen()
{
Gen<bool> a =
from i in Gen.Bool
from j in Gen.Bool
select !i;
}

[Fact]
public void CanUseSelectWithRange()
{
Range<int> a =
from i in Range.Constant(1, 10)
select i + 10;
}
}
}

0 comments on commit 6c22e89

Please sign in to comment.