-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let's use Expect
in all atoms
#3461
Comments
@yegor256 Should new Dataized(this.take(Attr.RHO)).asNumber() to this Expect.at(this, Attr.RHO)
.that(phi -> new Dataized(phi).asNumber())
.otherwise("Attr.RHO must be a number for 'EOnumber'")
.it(); |
@asmirnov-backend yes, definitely, this will be helpful |
While using Expect.at(this, Attr.RHO)
.that(phi -> new Dataized(phi).asNumber())
.otherwise("must be a number")
.it(); Perhaps it would be useful to have a more clever public class DataizableExpect {
private final Expect<Phi> expect;
public DataizableExpect(final Expect<Phi> expect) {
this.expect = expect;
}
public Double asDouble() {
return this.expect
.that(phi -> new Dataized(phi).asNumber())
.otherwise("must be a number")
.it();
}
public Integer asPositiveInt() {
return this.expect
.that(phi -> new Dataized(phi).asNumber())
.otherwise("must be a number")
.must(number -> number % 1 == 0)
.that(Double::intValue)
.otherwise("must be an integer")
.must(integer -> integer >= 0)
.otherwise("must be a positive integer")
.it();
}
} The code that uses this class would look something like this: new DataizableExpect(Expect.at(this, Attr.RHO)).asDouble() @yegor256 What do you think? |
@asmirnov-backend maybe we can make inner classes:
WDYT? |
@yegor256 Nice idea, thanks |
…for-some-atoms feat(#3461): Use Expect for EOnumber Atoms
Currently, we use
Expect
class just in a few atoms, where we want to have a detailed error reporting in case of user errors. Let's use it in all atoms.The text was updated successfully, but these errors were encountered: