Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noties/nullsafe
Null safe flow for Java & Android
https://github.com/noties/nullsafe
android java null
Last synced: 2 months ago
JSON representation
Null safe flow for Java & Android
- Host: GitHub
- URL: https://github.com/noties/nullsafe
- Owner: noties
- License: apache-2.0
- Created: 2017-10-26T13:04:45.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-27T09:21:00.000Z (about 7 years ago)
- Last Synced: 2023-07-07T14:17:22.922Z (over 1 year ago)
- Topics: android, java, null
- Language: Java
- Size: 58.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NullSafe
[![Maven Central](https://img.shields.io/maven-central/v/ru.noties/nullsafe.svg)](http://search.maven.org/#search|ga|1|g%3A%22ru.noties%22%20AND%20a%3A%22nullsafe%22)
Null safe flow for Java.
Java8:
```java
// `country` can be null, meaning that no mapping will occur and "Unknown" will be returned
final String name = NullSafe.create(country)
.map(Country::city) // map function will never call Supplier with null argument
.map(City::street)
.map(Street::name)
.get("Unknown");
``````java
final City capitalCity = capitalCity();
final String name = NullSafe.create(country)
.map(capitalCity, Country::city) // allows to specify def values (cannot be null)
.map(City::street)
.map(Street::name)
.get("Unknown");
``````java
// NullSafe instance can be used to split the flow (safe to reference intermediate state)
final NullSafe nullSafe = NullSafe.create(country)
.map(capitalCity, Country::city);final String name = nullSafe
.map(City::street)
.map(Street::name)
.get(); // <- returns nullable if no def value was specifiedfinal House house = nullSafe
.map(City::street)
.map(Street::house)
.get();
```This utility class is **not** thread-safe