Passed
Pull Request — master (#66)
by Hayrullah
56s
created

find_last.go   A

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gotil.FindLastBy 0 2 1
A gotil.FindLastByFromIndex 0 2 1
1
package gotil
2
3
import (
4
	"github.com/gotilty/gotil/internal"
5
)
6
7
// FindLastBy iterates over elements of collection, returns an object of lastest element predicate if returns true for.
8
// 		data := []int64{-100, -5, 30, 100}
9
// 		newData, _ := FindLastBy(data, func(val interface{}, i int) bool {
10
// 			if val.(int64) == 30 {
11
// 				return true
12
// 			} else {
13
// 				return false
14
// 			}
15
// 		})
16
// 		// Output: 30
17
func FindLastBy(a interface{}, f func(val interface{}, i int) bool) (interface{}, error) {
18
	return internal.FindLastBy(a, f)
19
}
20
21
// FindLastBy iterates over elements of collection, returns an object of lastest element predicate if returns true for.
22
// It works same as FindLastBy just from parameter provides to set start index of given slice or array.
23
func FindLastByFromIndex(a interface{}, f func(val interface{}, i int) bool, from int) (interface{}, error) {
24
	return internal.FindLastByFromIndex(a, f, from)
25
}
26