Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

iamceph/resulter

Repository files navigation

Resulter

Maven Central javadoc Codacy Badge

Tired of throwing exceptions or returning nonsense? Well, Resulter will save you!

Resultable

Resulter provides simple to use Results. Why? Well, there are few benefits.

  • Fewer exceptions or returning nonsense messages.
  • Clear understanding of what went wrong with message() and error() methods.
  • gRPC implementation.
  • Project Reactor support.

Dependency

The dependency for Resulter is available on Maven Central.

  • Gradle
implementation 'com.iamceph.resulter:resulter-core:1.1.6'
implementation("com.iamceph.resulter", "resulter-core", "1.1.6")
implementation("com.iamceph.resulter", "kotlin-extensions", "1.1.6")
  • Maven
<dependency>
    <groupId>com.iamceph.resulter</groupId>
    <artifactId>resulter-core</artifactId>
    <version>1.1.6</version>
</dependency>

Example

//this operation ended normally
public class Test {
    public Resultable doSomething() {
        Resultable okResult = Resultable.ok();

        //this operation failed because it cannot find given user.
        Resultable failedResult = Resultable.fail("Cannot find user!");
    }
}

Example usage

public class UserService {
    public Resultable isAccessAllowed(Integer userId) {
        if (userId == 1) {
            return Resultable.ok();
        }

        return Resultable.fail("User is not allowed to access.");
    }

    public DataResultable<User> anotherCheck(Integer userId) {
        //let's get if the user can enter
        final Resultable result = isAccessAllowed(userId);
        if (result.isFail()) {
            return result.transform();
        }

        //this will fail if the user does not exist in the repo, neat, right? :)
        return DataResultable.failIfNull(userRepository.findUser(userId));
    }
}

About

Tired of throwing exceptions or returning nonsense? Well, Resulter will save you!

Resources

License

Stars

Watchers

Forks

Packages

No packages published