Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
/ resulter Public archive

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

License

Notifications You must be signed in to change notification settings

iamceph/resulter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Novosad Frantisek
Mar 23, 2022
e7b653e · Mar 23, 2022

History

44 Commits
Mar 14, 2022
Dec 28, 2021
Mar 14, 2022
Mar 23, 2022
Aug 26, 2021
Jul 28, 2021
Mar 4, 2022
Mar 17, 2022
Dec 28, 2021
Aug 28, 2021
Aug 26, 2021
Jan 27, 2022
Jan 27, 2022

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));
    }
}