summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/funcdata
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/funcdata')
-rw-r--r--base/src/main/java/bjc/utils/funcdata/FunctionalList.java27
-rw-r--r--base/src/main/java/bjc/utils/funcdata/IList.java10
2 files changed, 37 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
index c730424..6953bd0 100644
--- a/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
+++ b/base/src/main/java/bjc/utils/funcdata/FunctionalList.java
@@ -169,6 +169,33 @@ public class FunctionalList<E> implements Cloneable, IList<E> {
}
@Override
+ public E last() {
+ if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to get last element of empty list");
+
+ return wrapped.get(wrapped.size() - 1);
+ }
+
+ @Override
+ public E popFirst() {
+ if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to pop first element of empty list");
+
+ E head = first();
+ wrapped.remove(0);
+
+ return head;
+ }
+
+ @Override
+ public E popLast() {
+ if(wrapped.size() < 1) throw new NoSuchElementException("Attempted to pop last element of empty list");
+
+ E tail = last();
+ wrapped.remove(wrapped.size() - 1);
+
+ return tail;
+ }
+
+ @Override
public <T> IList<T> flatMap(final Function<E, IList<T>> expander) {
if(expander == null) throw new NullPointerException("Expander must not be null");
diff --git a/base/src/main/java/bjc/utils/funcdata/IList.java b/base/src/main/java/bjc/utils/funcdata/IList.java
index cfda68d..12eaf2f 100644
--- a/base/src/main/java/bjc/utils/funcdata/IList.java
+++ b/base/src/main/java/bjc/utils/funcdata/IList.java
@@ -160,6 +160,16 @@ public interface IList<ContainedType> extends Iterable<ContainedType> {
ContainedType first();
/**
+ * Get the last element in the list.
+ *
+ * @return The last element in this list.
+ */
+ ContainedType last();
+
+ ContainedType popFirst();
+ ContainedType popLast();
+
+ /**
* Apply a function to each member of the list, then flatten the
* results.
*