Skip to content

Conversation

@jroper
Copy link
Contributor

@jroper jroper commented Nov 23, 2023

Sometimes you want to work with a StatusReply in the context of monadic processing with Try, Either or Option, rather than always pattern matching on it. This provides convenience methods to do that.

Sometimes you want to work with a StatusReply in the context of monadic
processing with Try, Either or Option, rather than always pattern matching on
it. This provides convenience methods to do that.
/**
* Return this StatusReply as a Try.
*/
def toTry: Try[T] = status
Copy link
Contributor

Choose a reason for hiding this comment

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

No problem with adding those. Normally StatusReply is supposed to be used with askWithStatus and the returned Future is already flattened to Future[T]. I guess you are using it without askWithStatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I was, I was refactoring some code that was using it, and found myself wanting to convert to either/try. But then as I expanded the scope of the refactoring, I found there was no good reason for it to be using a Future[StatusReply[T]] in the first place, that whatever errors it had were eventually flattened into a Future anyway, so I modified it to use askWithStatus. So, I don't actually have a use case for this now.

I think I would have more of a use case for map and flatMap on it, in the actor behaviour, the code I was working with was passing a lot of StatusReply types around when generating a reply, and although I didn't need these methods, I could see that they might be potentially useful. Though maybe the actor should have just worked with Try. But anyway, thats where toTrymight be useful, to do amapbefore converting back toStatusReply`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I suggest that we make this minimal by only adding toTry.

Java should already be covered by existing methods.

/**
* Return this StatusReply as an Option, returning None and discarding the error if it's an Error.
*/
def toOption: Option[T] = status.toOption
Copy link
Contributor

Choose a reason for hiding this comment

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

Add Scala API: to the docs of all 3 methods:

/**
   * Scala API: Return this StatusReply as an Option, returning None and discarding the error if it's an Error.
   */

Also add a def toOptional for Java.

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