Git Product home page Git Product logo

either.java's People

Contributors

hamishlawson avatar jartysiewicz avatar michaldo avatar peterunold avatar sfesenko avatar spencerwi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

either.java's Issues

Run method for Result

Hello,
I was very happy you made the effort to create this library.
Also I like how you added the Result-approach.

I am missing a run method for the Result class.
There is one in the Either so I will change my current usage of the library to the Either-Approach.

Result.flatMaps type signature is surprising

map and FlatMap have basically the same Type Signature apart from Exception Handling, which is wrong.

public abstract <T> Result<T> map(Function<R,T> transformValue);
public abstract <T> Result<T> flatMap(ExceptionThrowingFunction<R,T> transformValue);

Compared to flatMap on Scalas Try (or pretty much any other Class with flatMap in any functional Language):

 flatMap[U](f: (T) โ‡’ Try[U]): Try[U] 

I'd like to have a "real" flatMap Function. Catching Exceptions and translating to Result should be done by both, map and flatMap.

Either contains 2 value pointers instead of 1

What's the reason for using 2 value pointers per element instead of one:

public abstract class Either<L, R> {
    protected L leftValue;
    protected R rightValue;

It seems like every indirection via Either will double the required space for the pointers. Shy of a union type, you could have used java.lang.Object and cast it dynamically to L or R.

Result.map doesn't handle exceptions, as described in the readme

Next scenario from the readme fails, however it's expected that it'll wrap exceptions from chained methods

@Test
public void map() {
    Result<?> result = Result.attempt(() -> someOperationThatMightFailOrReturnA())
            .map(a -> someOtherOperationThatMightFailOReturnB(a))
            .map(b -> someThirdOperationThatMightFailOrReturnC(b));
    Assert.assertTrue(result.isErr());
}

private Object someThirdOperationThatMightFailOrReturnC(Object b) {
    return Objects.requireNonNull(b);
}

private Object someOtherOperationThatMightFailOReturnB(Object a) {
    return Objects.requireNonNull(a);
}

private Object someOperationThatMightFailOrReturnA() {
    return null;
}
java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:203)
	at com.spencerwi.either.ResultMapTest.someOtherOperationThatMightFailOReturnB(ResultMapTest.java:27)
	at com.spencerwi.either.ResultMapTest.lambda$map$1(ResultMapTest.java:16)
	at com.spencerwi.either.Result$Ok.map(Result.java:108)

License?

Hi @spencerwi,

I was wondering if you can think about and then add a license for this library (which is very nice and simple that's why I like it!).

Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.