Browse Source

added first()

Nicolas Cannasse 19 years ago
parent
commit
44766031ea
1 changed files with 9 additions and 0 deletions
  1. 9 0
      std/List.hx

+ 9 - 0
std/List.hx

@@ -65,6 +65,15 @@ class List<T> {
 		h = cons(item,h);
 	}
 
+	public function first() : T {
+		return switch h {
+		case empty:
+			null;
+		case cons(it,h):
+			it;
+		}
+	}
+
 	public function pop() : T {
 		return switch h {
 		case empty: