| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |