-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from adam-becker/split-modules
Split Property.fs across multiple files
- Loading branch information
Showing
10 changed files
with
242 additions
and
235 deletions.
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
[<AutoOpen>] | ||
module internal AutoOpen | ||
|
||
let flip f b a = f a b | ||
let inline always (a : 'a) (_ : 'b) : 'a = | ||
a | ||
|
||
let inline flip (f : 'a -> 'b -> 'c) (b : 'b) (a : 'a) : 'c = | ||
f a b |
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,36 @@ | ||
namespace Hedgehog | ||
|
||
[<Struct>] | ||
type Journal = | ||
| Journal of seq<unit -> string> | ||
|
||
module Journal = | ||
|
||
/// Creates a journal from a sequence of entries. | ||
let ofSeq (entries : seq<unit -> string>) : Journal = | ||
Journal entries | ||
|
||
/// Evaluates a single entry, returning it's message. | ||
let private evalEntry (f : unit -> string) : string = | ||
f() | ||
|
||
/// Evaluates all entries in the journal, returning their messages. | ||
let eval (Journal entries : Journal) : seq<string> = | ||
Seq.map evalEntry entries | ||
|
||
/// Represents a journal with no entries. | ||
let empty : Journal = | ||
ofSeq [] | ||
|
||
/// Creates a single entry journal from a given message. | ||
let singletonMessage (message : string) : Journal = | ||
ofSeq [ fun () -> message ] | ||
|
||
/// Creates a single entry journal from a given entry. | ||
let singleton (entry : unit -> string) : Journal = | ||
ofSeq [ entry ] | ||
|
||
/// Creates a journal composed of entries from two journals. | ||
let append (Journal xs) (Journal ys) : Journal = | ||
Seq.append xs ys | ||
|> ofSeq |
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,44 @@ | ||
namespace Hedgehog | ||
|
||
type Outcome<'a> = | ||
| Failure | ||
| Discard | ||
| Success of 'a | ||
|
||
module Outcome = | ||
|
||
let cata result failure discard success = | ||
match result with | ||
| Failure -> | ||
failure() | ||
| Discard -> | ||
discard() | ||
| Success(x) -> | ||
success(x) | ||
|
||
[<CompiledName("Map")>] | ||
let map (f : 'a -> 'b) (result : Outcome<'a>) : Outcome<'b> = | ||
cata result | ||
(always Failure) | ||
(always Discard) | ||
(f >> Success) | ||
|
||
[<CompiledName("Filter")>] | ||
let filter (f : 'a -> bool) (result : Outcome<'a>) : Outcome<'a> = | ||
let successOrDiscard x = | ||
if f x then | ||
Success(x) | ||
else | ||
Discard | ||
|
||
cata result | ||
(always Failure) | ||
(always Discard) | ||
successOrDiscard | ||
|
||
[<CompiledName("IsFailure")>] | ||
let isFailure (result : Outcome<'a>) : bool = | ||
cata result | ||
(always true) | ||
(always false) | ||
(always false) |
Oops, something went wrong.