Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/main/java/fj/data/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -1840,4 +1840,11 @@ private void copy() {
@Override public String toString() {
return Show.listShow( Show.<A>anyShow() ).show( this ).foldLeft((s, c) -> s + c, "" );
}

/**
* True if and only if the list has one element. Runs in constant time.
*/
public boolean isSingle() {
return isNotEmpty() && tail().isEmpty();
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/fj/data/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public static <T> Option<T> none() {
* return none, otherwise, return the given value in some.
*
* @param t The unsafe nullable value.
* @return If <code>t == null</code> then return it in some, otherwise, return none.
* @return If <code>t == null</code> then return none, otherwise, return it in some.
*/
public static <T> Option<T> fromNull(final T t) {
return t == null ? Option.<T>none() : some(t);
Expand All @@ -693,7 +693,7 @@ public static <T> Option<T> fromNull(final T t) {
* Turns an unsafe nullable value into a safe optional value. If <code>t == null</code> then
* return none, otherwise, return the given value in some.
*
* @return If <code>t == null</code> then return it in some, otherwise, return none.
* @return If <code>t == null</code> then return none, otherwise, return it in some.
*/
public static <T> F<T, Option<T>> fromNull() {
return t -> fromNull(t);
Expand Down