Skip to content

Commit 18ae251

Browse files
committed
Merge pull request #84 from dobesv/list-issingle
Merged #84: Add List.isSingle()
2 parents 7f8330b + abaf0ad commit 18ae251

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

core/src/main/java/fj/data/List.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,4 +1840,11 @@ private void copy() {
18401840
@Override public String toString() {
18411841
return Show.listShow( Show.<A>anyShow() ).show( this ).foldLeft((s, c) -> s + c, "" );
18421842
}
1843+
1844+
/**
1845+
* True if and only if the list has one element. Runs in constant time.
1846+
*/
1847+
public boolean isSingle() {
1848+
return isNotEmpty() && tail().isEmpty();
1849+
}
18431850
}

0 commit comments

Comments
 (0)