Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional implementations for Function.Util.safe #106

Closed
PromanSEW opened this issue Mar 5, 2017 · 2 comments
Closed

Additional implementations for Function.Util.safe #106

PromanSEW opened this issue Mar 5, 2017 · 2 comments

Comments

@PromanSEW
Copy link
Contributor

Where are implementations for IntFunction, LongFunction and DoubleFunction?
Example for IntFunction:

public static <T, R> IntFunction<T, R> safe(
                final ThrowableFunction<? super T, ? extends R, Throwable> throwableFunction,
                final R resultIfFailed) {
	return new IntFunction<R>() {
		@Override
		public R apply(int value) {
			try {
				return throwableFunction.apply(value);
			} catch (Throwable throwable) {
				return resultIfFailed;
			}
		}
	};
}

Will you add them?

@aNNiMON
Copy link
Owner

aNNiMON commented Mar 5, 2017

Okay. But it will be ThrowableIntFunction, ThrowableLongFunction etc to avoid unnecessary boxing.

@PromanSEW
Copy link
Contributor Author

PromanSEW commented Mar 5, 2017

I create this issue because I wanted to do mapToObj for IntStream with mapper throws JSONException, but I had to create this helper method, so LSA does not contain it for Stream of primitives
I know about Stream<Integer>.map method, which accepts Function created by safe method, but I want to avoid boxing

@aNNiMON aNNiMON closed this as completed in 51d69fe Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants