Bladeren bron

removed cmp argument from Lambda.has

Simon Krajewski 12 jaren geleden
bovenliggende
commit
dd1424faa3
2 gewijzigde bestanden met toevoegingen van 15 en 16 verwijderingen
  1. 9 16
      std/Lambda.hx
  2. 6 0
      tests/unit/unitstd/Lambda.unit.hx

+ 9 - 16
std/Lambda.hx

@@ -88,24 +88,17 @@ class Lambda {
 	}
 
 	/**
-		Tells if the element is part of an iterable. The comparison
-		is made using the [==] operator. Optionally you can pass as
-		a third parameter a function that performs the comparison.
-		That function must take as arguments the two items to
-		compare and returns a boolean value.
+		Tells if [it] contains [elt].
 		
-		TODO
+		This function returns true as soon as an element is found which is equal
+		to [elt] according to the [==] operator.
+		
+		If no such element is found, the result is false.
 	**/
-	public static function has<A>( it : Iterable<A>, elt : A, ?cmp : A -> A -> Bool ) : Bool {
-		if( cmp == null ) {
-			for( x in it )
-				if( x == elt )
-					return true;
-		} else {
-			for( x in it )
-				if( cmp(x,elt) )
-					return true;
-		}
+	public static function has<A>( it : Iterable<A>, elt : A ) : Bool {
+		for( x in it )
+			if( x == elt )
+				return true;
 		return false;
 	}
 

+ 6 - 0
tests/unit/unitstd/Lambda.unit.hx

@@ -49,6 +49,12 @@ b.pop() == 2;
 b.pop() == 4;
 b.pop() == 6;
 
+// has
+Lambda.has([1,2,3],1) == true;
+Lambda.has([1,2,3],4) == false;
+Lambda.has([],null) == false;
+Lambda.has([null],null) == true;
+
 // exists
 Lambda.exists([1, 2, 3], function(i) return i == 2) == true;
 Lambda.exists([1, 2, 3], function(i) return i == 4) == false;