Skip to content

Commit

Permalink
7.2.4-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Apr 12, 2017
1 parent 8d21cac commit cd426ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
31 changes: 16 additions & 15 deletions cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public interface Try<T,X extends Throwable> extends Supplier<T>, ValueObject, To
* Flatten a nested Try Structure
* @return Lowest nested Try
*/
public Try<T,X> flatten();
public <T> Try<T,X> flatten();

/**
* @return Optional present if Success, Optional empty if failure
Expand Down Expand Up @@ -319,24 +319,25 @@ public static class MyFinallyBlock<T,V,X extends Throwable> implements AndFinall
private final Class<X>[] classes;
private final CheckedSupplier<V,X> inputSupplier;
private final CheckedFunction<V, T, X> catchBlock;

private void invokeClose(Object in) {
if(in instanceof Iterable)
if(in instanceof Closeable || in instanceof AutoCloseable)
_invokeClose(in);
else if(in instanceof Iterable)
invokeClose((Iterable)in);
invokeClose((Closeable)in);
}
private void invokeClose(Iterable<Closeable> in){
for(Closeable next : in)
private void invokeClose(Iterable in){
for(Object next : in)
invokeClose(next);
}
private void invokeClose(Closeable in){
Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null)
.flatMap(m->Try.withCatch(()->m.invoke(in))
.filter(o->o!=null));


}
private void _invokeClose(Object in){

Try.withCatch(()->in.getClass().getMethod("close")).filter(m->m!=null)
.flatMap(m->Try.withCatch(()->m.invoke(in))
.filter(o->o!=null));

}
public Try<T,X> close(){

Expand Down
12 changes: 11 additions & 1 deletion cyclops-try/src/test/java/com/aol/cyclops/trycatch/TryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
import com.aol.cyclops.lambda.tuple.PTuple2;
import com.aol.cyclops.lambda.tuple.PowerTuples;
public class TryTest {



@Test
public void compileError(){
Try<String, Throwable> r = Try.of(Try.of("r"))
.flatten();




}
@Test(expected=IOException.class)
public void test(){
Try.runWithCatch(this::exceptional,IOException.class)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=7.2.0
version=7.2.4
lombokVersion=1.16.2
joolVersion=0.9.7
pcollectionsVersion=2.1.2
Expand Down

0 comments on commit cd426ef

Please sign in to comment.