about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-07-14 15:40:43 -0700
committerBrian Anderson <banderson@mozilla.com>2011-07-14 17:13:12 -0700
commit81acf69f9708a236ef78faa180575ae7b618fba9 (patch)
tree273c0d9b4daa9ffc91de1bf3ad5e8e060870bd12 /src/lib
parent139aaa1616fd341a71f0f11adb4e8850639e228c (diff)
downloadrust-81acf69f9708a236ef78faa180575ae7b618fba9.tar.gz
rust-81acf69f9708a236ef78faa180575ae7b618fba9.zip
Add head and tail functions to std::ivec
They even have typestate preconditions
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ivec.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/ivec.rs b/src/lib/ivec.rs
index 25e1e0118e8..10f5e33505b 100644
--- a/src/lib/ivec.rs
+++ b/src/lib/ivec.rs
@@ -87,6 +87,16 @@ pred is_not_empty[T](&T[mutable?] v) -> bool {
 
 // Accessors
 
+/// Returns the first element of a vector
+fn head[T](&T[mutable?] v) : is_not_empty(v) -> T {
+    ret v.(0);
+}
+
+/// Returns all but the first element of a vector
+fn tail[T](&T[mutable?] v) : is_not_empty(v) -> T[mutable?] {
+    ret slice(v, 1u, len(v));
+}
+
 /// Returns the last element of `v`.
 fn last[T](&T[mutable?] v) -> option::t[T] {
     if (len(v) == 0u) { ret none; }