forked from hedgehogqa/fsharp-hedgehog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some functional programming primitives related to Lazy
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Workaround for a Fable issue: https://github.com/fable-compiler/Fable/issues/2069 | ||
#if FABLE_COMPILER | ||
module Hedgehog.GenLazy | ||
#else | ||
[<RequireQualifiedAccess>] | ||
module internal Hedgehog.GenLazy | ||
#endif | ||
|
||
let constant a = a |> Lazy.constant |> Gen.constant | ||
|
||
let map f = f |> Lazy.map |> Gen.map | ||
|
||
let join glgla = glgla |> Gen.bind Lazy.value | ||
|
||
let bind f gla = gla |> map f |> join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Workaround for a Fable issue: https://github.com/fable-compiler/Fable/issues/2069 | ||
#if FABLE_COMPILER | ||
module Hedgehog.GenLazyTuple | ||
#else | ||
[<RequireQualifiedAccess>] | ||
module internal Hedgehog.GenLazyTuple | ||
#endif | ||
|
||
let mapFst f = f |> Tuple.mapFst |> GenLazy.map | ||
let mapSnd f = f |> Tuple.mapSnd |> GenLazy.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Workaround for a Fable issue: https://github.com/fable-compiler/Fable/issues/2069 | ||
#if FABLE_COMPILER | ||
module Hedgehog.Lazy | ||
#else | ||
[<RequireQualifiedAccess>] | ||
module internal Hedgehog.Lazy | ||
#endif | ||
|
||
let func (f: unit -> 'a) = Lazy<'a>(valueFactory = fun () -> f ()) | ||
|
||
let constant (a: 'a) = Lazy<'a>(valueFactory = fun () -> a) | ||
|
||
let value (ma: Lazy<'a>) = ma.Value | ||
|
||
let map (f: 'a -> 'b) (ma: Lazy<'a>) : Lazy<'b> = | ||
(fun () -> ma.Value |> f) | ||
|> func | ||
|
||
let join (mma: Lazy<Lazy<'a>>) = | ||
(fun () -> mma.Value.Value) | ||
|> func | ||
|
||
let bind (f: 'a -> Lazy<'b>) = | ||
f |> map >> join |