Skip to content

SeregaLBN/StreamUnthrower

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

StreamUnthrower

Main thing - see class Unthrow.java

Lets you use checked exception in lambda expressions. One import and use!

import utils.stream.Unthrow;
...
    static class BlaBla {
        void method() throws IOException { ... }
        boolean isSomething() throws IOException { ... }
    }

    public void blablaDemo() {
        // :)
        getBlaBlaList().stream()
                .filter( blaBla -> Unthrow.wrap(() -> blaBla.isSomething()) )
                .forEach(blaBla -> Unthrow.wrapProc(() -> blaBla.method()) );
        // :(
        getBlaBlaList().stream()
                .filter( blaBla -> { try { return blaBla.isSomething(); } catch (Exception ex) { throw new RuntimeException(ex); } } )
                .forEach(blaBla -> { try { blaBla.method(); } catch (Exception ex) { throw new RuntimeException(ex); } } );
    }
...

Full Demo example of use.

Comparison examples of usage:

Features:

  • it does not create new exceptions - re use existing
  • a minimum code
  • no substitution Stream, only the wrapper over the lambda

License

MIT

Free Software, Hell Yeah!

About

Exception in lambda expressions

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages