Skip to content
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

Implement MergeSources and BindReturn #4

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

michaelwinch
Copy link
Contributor

This will allow us to use and!

@michaelwinch michaelwinch requested a review from blair55 April 19, 2024 09:51
Copy link
Contributor

@blair55 blair55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementations are sound, but this won't result in and! making async calls parallel (if that's the intention in mediaingenuity/OpenBanking.AffordabilityInsights#12)

or is it still for the calling client to co-ordinate the parallelism, then zip together the responses?

Comment on lines +62 to +66
let zip left right =
match left, right with
| Ok x1res, Ok x2res -> Ok(x1res, x2res)
| Error e, _ -> Error e
| _, Error e -> Error e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparing with FsToolKit Result.zip

seems fine but looks like they have a typo in the comment: // Ok (Some(1, 2)) ?

worth a PR there, too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 30 to 31
let zip left right =
bind (fun l -> bind (fun r -> retn (l, r)) right) left
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally think the CE is more readable in this case rather than nested inline functions. Tho maybe not so straight forward in the 'deeper' types? logaf low.

Suggested change
let zip left right =
bind (fun l -> bind (fun r -> retn (l, r)) right) left
let zip left right =
async {
let! l = left
let! r = right
return (l, r)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking to keep it using bind just because the zip definition should be the same in any context so if we need to implement a zip in another CE we can just copy paste this line. I've updated it to work in parallel now thought based on Don Syme's recommendation in this comment dotnet/fsharp#11043 (comment)

@@ -262,6 +288,8 @@ type AsyncWriterResultBuilder() =
member __.ReturnFrom(m: Async<Writer<'w, Result<'a, 'b>>>) = m
member __.Bind(m, f) = AsyncWriterResult.bind f m
member __.Zero() = __.Return()
member __.BindReturn(x, f) = AsyncWriterResult.map f x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't realise BindReturn is just map!

is it possible to use map "on its own" in a CE? as in, does the ! syntax support it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry not quite sure what you mean by this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea ignore me 😅

I'm imagining a world where let! = works on a function that just maps, but I guess that's just let =

@michaelwinch michaelwinch requested a review from blair55 April 23, 2024 14:04
@michaelwinch michaelwinch merged commit 274fb6c into totallymoney:master Apr 25, 2024
1 check passed
@michaelwinch michaelwinch deleted the implement-and-bang branch April 25, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants