aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: d213621f70a87a8a8071b5c517297485170c3db9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# extended-functions

A small project providing extensions and additions to Java 8's built-in functions.

## installation

Add the following to your pom.xml's dependencies:
	
```xml
<dependencies>
	...
	<dependency>
		<groupId>com.github.markozajc</groupId>
		<artifactId>extended-functions</artifactId>
		<version>1.0</version>
	</dependency>
	...
</dependencies>
```

or your build.gradle:

```groovy
repositories {
	...
	mavenCentral()
	...
}

dependencies {
	...
	api 'com.github.markozajc:extended-functions:1.0'
	...
}
```
	
## usage

Some of this project's additions do not extend Java 8's built-in functions and can therefore not be used directly with Java's APIs. However, those that do (specifically certain E\* and AE\* ones) can be through casting. For example, one can use:

```java
files.forEach((EConsumer<Path, IOException>) Files::delete);
```

or with the catch-all-exceptions AE\* type:

```java
files.forEach((AEConsumer<Path>) Files::delete);
```

rather than the vanilla way of doing it:

```java
files.forEach(t -> {
	try {
		Files.delete(t);
	} catch (IOException e) {
		// the error handling logic
	}
});
```

Note, however, that checked exceptions are _not_ wrapped into RuntimeException - they are instead rethrown directly using a generics hack (see com.github.markozajc.functions.exceptionable.Utilities). This unfortunately also means that they can't be caught directly, because javac will complain that `exception XYZException is never thrown in body of corresponding try statement`. You can get around that by declaring `throws` on the method itself, or by catching `Exception` and then running your handling logic based on `instanceof`.