Explorar o código

added first()

Nicolas Cannasse %!s(int64=19) %!d(string=hai) anos
pai
achega
44766031ea
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  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: