-
The following code is now giving me an error message saying:
When I moved from v4 to v5-latest. Does anyone have any examples of what I should do? Also is v5 technically stable enough to use at my company? I'm currently tasked with building a foundation for a large re-write and they've allowed me to explore this library on work hours because I've made such a good case for FP. I want to make sure that I give this library a good first impression. public class DocumentRepository : IDocumentRepository
{
public Eff<Option<Document>> GetDocumentByIdAsync(DocumentDbContext context, Guid id) =>
Eff<Option<Document>>.Effect(async () => {
var document = await context.Set<Document>().FindAsync(id);
return (document == null)
? Option<Document>.None
: Option<Document>.Some(document);
});
public Eff<Option<Lst<Document>>> GetAllDocumentsAsync(DocumentDbContext context) =>
Eff<Option<Lst<Document>>>.Effect(async () => {
var documents = await context.Set<Document>().ToListAsync();
return documents.Count > 0
? Option<Lst<Document>>.Some(new Lst<Document>(documents))
: Option<Lst<Document>>.None;
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
I just noticed that ".Effect" is deprecated. I replaced with LiftIO and the error has gone away, but I'm not sure if this is the correct way to implement this. The documentation of Effect just does |
Beta Was this translation helpful? Give feedback.
-
Everything that can do Every type that does IO usually has some bespoke functionality for lifting
|
Beta Was this translation helpful? Give feedback.
It seems to me to be a mistake to take a
Validation
as an argument. You should only callAddDocumentAsync
with a validDocument
, 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:
In terms of inference, C# infers mo…