Skip to content

Async Effects changes between v4 and v5 #1393

Answered by louthy
rhemsuda asked this question in Q&A
Discussion options

You must be logged in to vote

It seems to me to be a mistake to take a Validation as an argument. You should only call AddDocumentAsync with a valid Document, not one that might be invalid and cause the function to early-out and do nothing. The acquisition of the document should happen outside of the function imho.

That would simplify your code somewhat:

public Eff<Either<AddDocumentError, Document>> AddDocumentAsync(
    DocumentDbContext context,
    Document document) =>
    from d in liftEff(() => context.Set<Document>().FindAsync(document.ID))
    select d is null
               ? Right(document)
               : Left<AddDocumentError, Document>(new AddDocumentError.Exists(d));

In terms of inference, C# infers mo…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@rhemsuda
Comment options

@louthy
Comment options

@rhemsuda
Comment options

@louthy
Comment options

Answer selected by rhemsuda
@rhemsuda
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants