monads

A library of monads for Java

License

License

MIT
GroupId

GroupId

com.github.rutledgepaulv
ArtifactId

ArtifactId

monads
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

monads
A library of monads for Java
Project URL

Project URL

https://github.com/rutledgepaulv/monads
Source Code Management

Source Code Management

https://github.com/rutledgepaulv/monads

Download monads

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.rutledgepaulv/monads/ -->
<dependency>
    <groupId>com.github.rutledgepaulv</groupId>
    <artifactId>monads</artifactId>
    <version>0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.rutledgepaulv/monads/
implementation 'com.github.rutledgepaulv:monads:0.5'
// https://jarcasting.com/artifacts/com.github.rutledgepaulv/monads/
implementation ("com.github.rutledgepaulv:monads:0.5")
'com.github.rutledgepaulv:monads:jar:0.5'
<dependency org="com.github.rutledgepaulv" name="monads" rev="0.5">
  <artifact name="monads" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.rutledgepaulv', module='monads', version='0.5')
)
libraryDependencies += "com.github.rutledgepaulv" % "monads" % "0.5"
[com.github.rutledgepaulv/monads "0.5"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Maven Central

Monads

Basic useful monads missing from Java.

Lazy

// maintain the lazy as a memoizing supplier
// every time you call .get() you get the same instance
private Lazy<UserService> userService = Lazy.of(UserServiceImpl::new);

// create a proxy for the interface that delegates to a lazy instance.
// this means that the instance only gets created once you call a method on the proxy.
private UserService userService = Lazy.proxy(UserService.class, UserServiceImpl::new);

Try

public String getUserDisplay(String username) {
    return queryDatabase(username)
            .map(User::getDisplayName)
            .recover(NotFoundException.class, ex -> "User not found.")
            .recover(IOException.class, ex -> "Error communicating with database.")
            .onFailure(Exception.class, ex -> logger.error("Encountered unhandled error.", ex))
            .get();
}

// by returning a Try from your methods that can fail with exceptions you
// provide a control mechanism to the higher layers in your application 
// which are the ones that actually know enough to decide how to respond 
// to failures
public Try<User> queryDatabase(String username) {
    return Try.of(() -> findOne(where("username").is(username)));
}

Release Versions

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>monads</artifactId>
        <version>0.5</version>
    </dependency>
</dependencies>

Snapshot Versions

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>monads</artifactId>
        <version>0.6-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>ossrh</id>
        <name>Repository for snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

License

This project is licensed under MIT license.

Versions

Version
0.5