-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.go
More file actions
27 lines (23 loc) · 780 Bytes
/
Copy pathapi.go
File metadata and controls
27 lines (23 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Package get provides conditional expression builders
package get
import "github.com/m4gshm/gollections/expr/use"
// If builds a head of getter function call by condition.
// Looks like val := get.If(condition, getterFuncOnTrue).Else(defaltVal) tha can be rewrited by:
//
// var val type
// if condtion {
// val = getterFuncOnTrue()
// } else {
// val = defaltVal
// }
func If[T any](condition bool, then func() T) use.When[T] {
return use.IfGet(condition, then)
}
// IfErr is like If but aimed to use an error return function
func IfErr[T any](condition bool, then func() (T, error)) use.WhenErr[T] {
return use.IfGetErr(condition, then)
}
// If_ is alias of IfErr
func If_[T any](condition bool, tru func() (T, error)) use.WhenErr[T] {
return IfErr(condition, tru)
}