소스 검색

added first()

Nicolas Cannasse 19 년 전
부모
커밋
44766031ea
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  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: