Skip to content

StefanMacke/ao-railway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ao-railway

A library for Railway Oriented Programming with Java.

See Scott Wlaschin's talk on the subject for more information: Scott Wlaschin - Railway Oriented Programming - error handling in functional languages.

Example

Result.combine(
                Result.with(username, "Username cannot be empty"),
                Result.with(oldPassword, "Old password cannot be empty"),
                Result.with(newPassword, "New password cannot be empty"))
                .onSuccess(() -> userRepo.find(username))
                .ensure(user -> user.isCorrectPassword(oldPassword), "Invalid password")
                .onSuccess(user -> user.changePassword(newPassword))
                .onSuccess(user -> userRepo.update(user))
                .onFailure(() -> logger.error("Password could not be changed"))
                .map(user -> user);

Or start with com.example.Main class.

About

Railway Oriented Programming in Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages