<commit_before># io.meat:try
### A humble Try monad for Java 8

A Try is a completed attempt to compute a result that either succeeded or
failed.

Try is especially useful for monadic composition of tasks that may each fail,
without having to use a series of nested try/catch statements.  You can form a
Try using `attempt()` or `attemptApply()`:

```java
Try<String> value = Try.attempt(() -> keyValueStore.fetch("someKey"));
Try<String> value = Try.attemptApply(keyValueStore::fetch, "someKey");
```

If the function has checked exceptions, you can use `attemptChecked()` or
`attemptApplyChecked()` to wrap any exception in a RuntimeException.

You can also manually make a successful or failed Try using `succeed()` and
`fail()`:

```java
Try<String> value = Try.succeed("someValue");
Try<String> failure = Try.fail(new IllegalStateException("Something broke"));
```

Once you have a Try, you can transform the value inside it using `map()`:

```java
Try<String> hex = Try.succeed(123).map(Integer::toHexString);
assert hex.equals(Try.succeed("7b"));
```

If your function returns a Try, you can use `flatMap()` to prevent nesting:

```java
Try<Integer> number = Try.succeed(123);
Try<String> nextValue = number.flatMap(num -> {
    return Try.succeed("a string");
});
assert nextValue.equals(Try.succeed("a string"));
```

To get values back out of a Try, there are Optionals available as `getResult()`
and `getFailure()` for safe retrieval of either state:

```java
Try<Integer> number = Try.succeed(123);
assert number.getResult().equals(Optional.of(123));
assert !number.getFailure().isPresent();
```

If you've checked that a Try is successful, or you don't mind an (unchecked)
exception being raised, use `get()`:

```java
Try<Integer> number = Try.succeed(123);
assert number.get() == 123;
```

In the case of a failed Try, `get()` will wrap the exception in a
`RuntimeException`; its `Throwable.getCause()` will be the original exception.
<commit_msg>A bit more README.<commit_after># io.meat:try
### A humble Try monad for Java 8

A Try is a completed attempt to compute a result that either succeeded or
failed.

## Quickstart

Try is especially useful for monadic composition of tasks that may each fail,
without having to use a series of nested try/catch statements.  You can form a
Try using `attempt()` or `attemptApply()`:

```java
Try<String> value = Try.attempt(() -> keyValueStore.fetch("someKey"));
Try<String> value = Try.attemptApply(keyValueStore::fetch, "someKey");
```

If the function has checked exceptions, you can use `attemptChecked()` or
`attemptApplyChecked()` to wrap any exception in a RuntimeException.

You can also manually make a successful or failed Try using `succeed()` and
`fail()`:

```java
Try<String> value = Try.succeed("someValue");
Try<String> failure = Try.fail(new IllegalStateException("Something broke"));
```

Once you have a Try, you can transform the value inside it using `map()`:

```java
Try<String> hex = Try.succeed(123).map(Integer::toHexString);
assert hex.equals(Try.succeed("7b"));
```

If your function returns a Try, you can use `flatMap()` to prevent nesting:

```java
Try<Integer> number = Try.succeed(123);
Try<String> nextValue = number.flatMap(num -> {
    return Try.succeed("a string");
});
assert nextValue.equals(Try.succeed("a string"));
```

To get values back out of a Try, there are Optionals available as `getResult()`
and `getFailure()` for safe retrieval of either state:

```java
Try<Integer> number = Try.succeed(123);
assert number.getResult().equals(Optional.of(123));
assert !number.getFailure().isPresent();
```

If you've checked that a Try is successful, or you don't mind an (unchecked)
exception being raised, use `get()`:

```java
Try<Integer> number = Try.succeed(123);
assert number.get() == 123;
```

In the case of a failed Try, `get()` will wrap the exception in a
`RuntimeException`; its `Throwable.getCause()` will be the original exception.

## API Docs

The API docs are hosted [on Github Pages](http://zacharyvoase.github.io/try/apidocs/).

{'fraction_non_alphanumeric': 0.1349814585908529, 'fraction_numerical': 0.009888751545117428, 'mean_word_length': 5.371653543307087, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4636223', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1172, 'n_words': 476}