Skip to content

Consider adding jOOL-like Syntax #5

Description

@DavidTheExplorer

I have been using this library for quite a while, and I can't recall one place where I didn't use Exceptions.sneak()#method.
Consider this example:

List<Path> nonEmptyFiles = Files.list(somePath)
                .filter(path -> Exceptions.sneak().get(() -> Files.readString(path)).isEmpty())
                .toList();

The filter is ugly and takes too much time to understand for its purpose.
My suggestion is to allow users to choose their preferred ExceptionHandler - so 99% of the time the syntax is clearer and shorter:

.filter(path -> Unchecked.get(() -> Files.readString(path)).isEmpty())



P.S: I know the example can be rewritten using map/filter, but it still feels like too much...

.map(Exceptions.sneak().function(Files::readString))
.filter(not(String::isEmpty)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions