-
Notifications
You must be signed in to change notification settings - Fork 0
Remove internal scoping and add Async extension methods for validation contexts #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
src/FSharp.Data.Validation.Async/FSharp.Data.Validation.Async.fsproj
This file contains hidden or 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,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="VCtx.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\FSharp.Data.Validation\FSharp.Data.Validation.fsproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,71 @@ | ||
| namespace FSharp.Data.Validation | ||
|
|
||
| [<RequireQualifiedAccess>] | ||
| module VCtx = | ||
| /// <summary> | ||
| /// Binds a function that returns an asynchronous computation to a validation context. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This function takes a function <c>fn</c> that transforms a value of type <c>'A</c> into an | ||
| /// asynchronous computation of type <c>Async<VCtx<'F, 'B>></c> and a validation context <c>c</c> | ||
| /// of type <c>VCtx<'F, 'A></c>. It returns an asynchronous computation of type <c>Async<VCtx<'F, 'B>></c>. | ||
| /// | ||
| /// The function handles the following cases: | ||
| /// <list type="bullet"> | ||
| /// <item> | ||
| /// <description><c>ValidCtx a</c>: Applies the function <c>fn</c> to <c>a</c> and returns the result.</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <description><c>RefutedCtx (gfs, lfs)</c>: Returns the same <c>RefutedCtx</c> without applying the function.</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <description><c>DisputedCtx (gfs, lfs, a)</c>: Applies the function <c>fn</c> to <c>a</c> and merges the results accordingly.</description> | ||
| /// </item> | ||
| /// </list> | ||
| /// </remarks> | ||
| /// <param name="fn">A function that takes a value of type <c>'A</c> and returns an asynchronous computation of type <c>Async<VCtx<'F, 'B>></c>.</param> | ||
| /// <param name="c">A validation context of type <c>VCtx<'F, 'A></c>.</param> | ||
| /// <returns>An asynchronous computation of type <c>Async<VCtx<'F, 'B>></c>.</returns> | ||
| let bindToAsync (fn:'A -> Async<VCtx<'F, 'B>>) (c: VCtx<'F, 'A>): Async<VCtx<'F, 'B>> = | ||
| async { | ||
| match c with | ||
| | ValidCtx a -> return! fn a | ||
| | RefutedCtx (gfs,lfs) -> return RefutedCtx (gfs,lfs) | ||
| | DisputedCtx (gfs,lfs,a) -> | ||
| let! b = fn a | ||
| match b with | ||
| | ValidCtx b -> return DisputedCtx (gfs,lfs,b) | ||
| | DisputedCtx (gfs',lfs',b) -> return DisputedCtx (gfs @ gfs', Utilities.mergeFailures lfs lfs', b) | ||
| | RefutedCtx (gfs',lfs') -> return RefutedCtx (gfs @ gfs', Utilities.mergeFailures lfs lfs') | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Binds a function that returns a validation context to an asynchronous computation. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This function takes a function <c>fn</c> that transforms a value of type <c>'A</c> into a validation context | ||
| /// of type <c>VCtx<'F, 'B></c> and an asynchronous computation <c>c</c> of type <c>Async<VCtx<'F, 'A>></c>. | ||
| /// It returns an asynchronous computation of type <c>Async<VCtx<'F, 'B>></c>. | ||
| /// </remarks> | ||
| /// <param name="fn">A function that takes a value of type <c>'A</c> and returns a validation context of type <c>VCtx<'F, 'B></c>.</param> | ||
| /// <param name="c">An asynchronous computation of type <c>Async<VCtx<'F, 'A>></c>.</param> | ||
| /// <returns>An asynchronous computation of type <c>Async<VCtx<'F, 'B>></c>.</returns> | ||
| let bindAsync (fn:'A -> Async<VCtx<'F, 'B>>) (c: Async<VCtx<'F, 'A>>): Async<VCtx<'F, 'B>> = | ||
| async { | ||
| let! c' = c | ||
| return! bindToAsync fn c' | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Binds a function that returns a validation context to a validation context. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This function takes a function <c>fn</c> that transforms a value of type <c>'A</c> into a validation context | ||
| /// of type <c>VCtx<'F, 'B></c> and a validation context <c>c</c> of type <c>VCtx<'F, 'A></c>. | ||
| /// It returns a validation context of type <c>VCtx<'F, 'B></c>. | ||
| /// </remarks> | ||
| /// <param name="fn">A function that takes a value of type <c>'A</c> and returns a validation context of type <c>VCtx<'F, 'B></c>.</param> | ||
| /// <param name="c">A validation context of type <c>VCtx<'F, 'A></c>.</param> | ||
| /// <returns>A validation context of type <c>VCtx<'F, 'B></c>.</returns> | ||
| let bindFromAsync (fn:'A -> VCtx<'F, 'B>) (c: Async<VCtx<'F, 'A>>): Async<VCtx<'F, 'B>> = | ||
| bindAsync (fn >> async.Return) c |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devinlyons Does it make sense to release this in lock-step with FSharp.Data.Validation? I opted to do it this way since it directly references FSharp.Data.Validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That direct reference will be converted to a NuGet reference. However, the version range will be locked down to the exact version. I guess that's a long way of saying yes, let's release them in lock step.