diff --git a/LICENSE b/LICENSE
index 5b0fbd5..e460c34 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2012, Martin Angers & Contributors
+Copyright (c) 2012-2013, Martin Angers & Contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
diff --git a/bench/v0.1.1-v0.2.1-go1.1rc1.svg b/bench/v0.1.1-v0.2.1-go1.1rc1.svg
new file mode 100644
index 0000000..849a70b
--- /dev/null
+++ b/bench/v0.1.1-v0.2.1-go1.1rc1.svg
@@ -0,0 +1,405 @@
+
+
+
diff --git a/bench/v0.2.0-v0.2.1-go1.1rc1.svg b/bench/v0.2.0-v0.2.1-go1.1rc1.svg
new file mode 100644
index 0000000..eaabc61
--- /dev/null
+++ b/bench/v0.2.0-v0.2.1-go1.1rc1.svg
@@ -0,0 +1,420 @@
+
+
+
diff --git a/doc.go b/doc.go
index e98eb50..edc21c3 100644
--- a/doc.go
+++ b/doc.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, Martin Angers & Contributors
+// Copyright (c) 2012-2013, Martin Angers & Contributors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -60,6 +60,7 @@ The various methods are split into files based on the category of behavior:
* iteration.go : methods to loop over the selection's nodes.
- Each()
+ - EachWithBreak()
- Map()
* property.go : methods that inspect and get the node's properties values.
diff --git a/iteration.go b/iteration.go
index ff07f29..fd70b90 100644
--- a/iteration.go
+++ b/iteration.go
@@ -9,6 +9,19 @@ func (this *Selection) Each(f func(int, *Selection)) *Selection {
return this
}
+// EachWithBreak() iterates over a Selection object, executing a function for each
+// matched element. It is identical to `Each()` except that it is possible to break
+// out of the loop by returning `false` in the callback function. It returns the
+// current Selection object.
+func (this *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
+ for i, n := range this.Nodes {
+ if !f(i, newSingleSelection(n, this.document)) {
+ return this
+ }
+ }
+ return this
+}
+
// Map() passes each element in the current matched set through a function,
// producing a slice of string holding the returned values.
func (this *Selection) Map(f func(int, *Selection) string) (result []string) {
diff --git a/iteration_test.go b/iteration_test.go
index a662ad2..d1bb748 100644
--- a/iteration_test.go
+++ b/iteration_test.go
@@ -19,6 +19,21 @@ func TestEach(t *testing.T) {
AssertLength(t, sel.Nodes, 6)
}
+func TestEachWithBreak(t *testing.T) {
+ var cnt int
+
+ sel := Doc().Find(".hero-unit .row-fluid").EachWithBreak(func(i int, n *Selection) bool {
+ cnt++
+ t.Logf("At index %v, node %v", i, n.Nodes[0].Data)
+ return false
+ }).Find("a")
+
+ if cnt != 1 {
+ t.Errorf("Expected Each() to call function 1 time, got %v times.", cnt)
+ }
+ AssertLength(t, sel.Nodes, 6)
+}
+
func TestEachEmptySelection(t *testing.T) {
var cnt int