Replies: 5 comments
-
You bind the var bindWayResult = await GetFolder("123")
.Bind(folder => CreateFolder("New folder", folder))
.Bind(createdFolderResult => UploadFile(Stream.Null, "New file name.txt", "text/text", createdFolderResult))
.Match(successValue => successValue, exception => $"Exception: {exception.Message}");
var linqWayOperation =
from folder in GetFolder("123")
from createdFolderResult in CreateFolder("New folder", folder)
from uploadFileResult in UploadFile(Stream.Null, "New file name.txt", "text/text", createdFolderResult)
select uploadFileResult;
var linqWayOperationResult = await linqWayOperation
.Match(successValue => successValue, exception => $"Exception: {exception.Message}"); You can also use |
Beta Was this translation helpful? Give feedback.
-
@Malgefor Thanks for the reply, but unfortunately, it didn't work. I copied your first example (as I prefer the method syntax), and changed the second parameter to the var bindWayResult = await GoogleDriveHelper.GetFolder("123")
.Bind(folder => GoogleDriveHelper.CreateFolder("New folder", folder.Id))
.Bind(createdFolderResult => GoogleDriveHelper.UploadFile(Stream.Null, "New file name.txt", "text/text", createdFolderResult))
.Match(successValue => successValue, exception => $"Exception: {exception.Message}"); However, that gave me a compiler error on the first call to The type arguments for method 'TryAsyncExtensions.Bind<A, B>(TryAsync, Func<A, TryAsync>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. Hovering over the Any ideas? Thanks again. |
Beta Was this translation helpful? Give feedback.
-
When I copy your code it compiles just fine. I think the problem is something else than the
|
Beta Was this translation helpful? Give feedback.
-
@Malgefor Duh, you got it! I had forgotten that when I first wrote these methods, I went through a few iterations of using the wrong monads. The previous iteration returned an With a dummy body for Thanks again. If I get stuck on converting, I'll open a new issue. |
Beta Was this translation helpful? Give feedback.
-
@Malgefor Got stuck with that last method. I opened a new issue, so if there's any chance you could take a look, I'd really appreciate it. Thanks again |
Beta Was this translation helpful? Give feedback.
-
Suppose I have the following methods...
...where
File
is a Google type for files/folders in a Google Drive.I can call each of these individually, no problem. However, I sometimes want to call more than one, say to get the
File
object for a specific folder, then create a new subfolder and upload a file to it. I know I can do this as follows (air code, so please ignore any typos)...As you can see, this is very painful. I am sure that you are supposed to be able to chain monads together, I think using
Bind
, so you end up with something more like this (again, air code)...However, I can't get any code to compile like this.
Anyone able to advise how I can improve the nested monads I have? Thanks
Beta Was this translation helpful? Give feedback.
All reactions