Replies: 2 comments 4 replies
-
Depends on your needs, but if you fire and forget, then why do you need to fail on None?
No it doesn't, judging by the code it returns |
Beta Was this translation helpful? Give feedback.
-
Just don't If you want to follow the advice (avoid calling
It also returns an public readonly record struct ForkIO<A>(
IO<Unit> Cancel,
IO<A> Await);That means you can compute I would really encourage you to think about what it means when a computation is represented as an Something like this: await marketplaceApi
.GetItemTitle(itemId)
.Bind(option =>
option.Match(
Some: itemTitle => notificationsApi.NotifyUserByEmail(
recipientUserId,
$"You have a new message from {itemTitle} seller.",
msg.Content
),
None: () => Error.Empty
)
)
.RunAsync();Could be written as: // This is a simple static class that represents the 'edge' of your application, the idea is that
// we package up calls to other static `IO` yielding types and run them to get the underlying
// task.
public static ServiceRequest
{
public static ValueTask<A> Foo(ItemId itemId, MarketPlace API api) =>
ServiceAPI.Foo(itemId, api).RunAsync();
}
// This is where you keep your pure application logic. NEVER leave IO once you're in it, it makes
// it much easier to leverage the underlying capabilities of the IO monad, but also each methoid
// should be pure. Which means composition for free.
public static ServiceAPI
{
public static IO<A> Foo(ItemId itemId, MarketPlace API api)
api.GetItemTitle(itemId)
.Bind(option =>
option.Match(
Some: itemTitle => notificationsApi.NotifyUserByEmail(
recipientUserId,
$"You have a new message from {itemTitle} seller.",
msg.Content),
None: () => Error.Empty));
}The exact approach should be yours, of course, but writing your pure logic in one place and then only computing it at the edges will give you superpowers. There are also various samples that demonstrate forking, so it's worth searching the repo for 'fork'. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I need to fire and forget this piece of code, also I want do nothing or maybe just log something on none so idk if its good to just return empty error?
GetItemTitlereturnsIO<string>NotifyUserByEmailreturnsIO<Unit>Beta Was this translation helpful? Give feedback.
All reactions