Commits

Anonymous committed a23651c

Making sure we handle the non-indexed where predicate properly

  • Participants
  • Parent commits 404e058

Comments (0)

Files changed (2)

ActionLinqTests/src/flexUnitTests/WhereTests.as

 		}
 		
 		[Test]
+		public function Static_Predicate_Without_Indexer_Doesnt_Fail(): void
+		{
+			var data:Array = [1, 2, 3, 4, 5];
+			var filtered:IEnumerable = data.Where(GreaterOrEqualTo4);
+			var enumerator:IEnumerator = filtered.GetEnumerator();
+			
+			assertThat(enumerator.MoveNext(), equalTo(true));
+			assertThat(enumerator.Current(), equalTo(4));
+			assertThat(enumerator.MoveNext(), equalTo(true));
+			assertThat(enumerator.Current(), equalTo(5));
+			assertThat(enumerator.MoveNext(), equalTo(false));
+		}
+		
+		private function GreaterOrEqualTo4(i:int):Boolean {
+			return i >= 4;
+		}
+		
+		[Test]
 		public function Where_With_Index_Passes_Index_If_Defined():void {
 			var data:Array = 
 				[1, 2, 3, 4, 5]

Linq/src/System/Linq/WhereEnumerator.as

 		{
 			while(enumerator.MoveNext())
 			{
-				if(predicate(enumerator.Current(), ++count))
+				var matched:Boolean = predicate.length == 1 ? 
+					predicate(enumerator.Current()) : 
+					predicate(enumerator.Current(), ++count);
+				
+				if(matched)
 					return true;
 			}