Skip to content

Commit a67789f

Browse files
flyznexdineshba
authored andcommitted
changed
1 parent 3e79dce commit a67789f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

find.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
//
1010
// Input of type slice is supported as of now.
1111
// Output is a elements are matched.
12-
// PredicateFn function is applied on each element of input to determine to find element
12+
// PredicateFn function is applied on each element of input to determine to find element until it finds the element
1313
//
1414
// Validations:
1515
//
@@ -55,7 +55,7 @@ func Find(in, out, predicateFn interface{}) error {
5555
return nil
5656
}
5757
}
58-
58+
return fmt.Errorf("element not found")
5959
}
6060
return fmt.Errorf("not implemented")
6161
}

find_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ func TestFind(t *testing.T) {
8383
assert.EqualError(t, err, "input slice (int) and output (string) should be of the same Type")
8484
})
8585

86+
t.Run("should return error if element not found", func(t *testing.T) {
87+
in := []int{1, 2, 3}
88+
{
89+
var out int
90+
91+
err := godash.Find(in, &out, func(x int) bool { return x == 4 })
92+
93+
assert.EqualError(t, err, "element not found")
94+
}
95+
{
96+
var out int
97+
err := godash.Find(in, &out, func(x int) bool { return x == 1 })
98+
assert.NoError(t, err)
99+
}
100+
})
101+
86102
}
87103

88104
func ExampleFind() {
@@ -94,7 +110,7 @@ func ExampleFind() {
94110
var output string
95111

96112
_ = godash.Find(input, &output, func(in string) bool {
97-
return strings.HasPrefix(in, "r") // starts with
113+
return strings.HasPrefix(in, "r")
98114
})
99115
fmt.Println(output)
100116

0 commit comments

Comments
 (0)