Skip to content

Archenoth/Result

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A destructurable Result type for Java 21+!

This library is a simple Result sealed interface allowing you to eliminate null in all kinds of places in a way that Rustaceans have enjoyed for a long time~

Meaning you can do things like this!

if(somethingThatReturnsAResult() instanceof Some(File found)){
    file.delete();
}

or this!

return switch(somethingThatReturnsAResult()){
    case Some(String message) -> message;
    case None() -> "Uh oh, nothing??";
};

or even this!

return switch(somethingThatReturnsAResult()){
    case Some(val num) when num == 1 -> num + " thing";
    case Some(val num) -> num + " things!";
    case None() -> "Uh oh, nothing??";
};

All you need to do is wrap your return value with a Result.of(). It even works with wrapped Optional values!