mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-30 00:46:08 +03:00
36 lines
566 B
Go
36 lines
566 B
Go
package main
|
|
|
|
func main() {
|
|
|
|
}
|
|
|
|
type SuccessFunc func(string)
|
|
type FailFunc func(error)
|
|
type ExecuteStringFunc func() (string, error)
|
|
|
|
type MaybeString struct {
|
|
successFunc SuccessFunc
|
|
failFunc FailFunc
|
|
}
|
|
|
|
func (s *MaybeString) Success(f SuccessFunc) *MaybeString {
|
|
s.successFunc = f
|
|
return s
|
|
}
|
|
|
|
func (s *MaybeString) Fail(f FailFunc) *MaybeString {
|
|
s.failFunc = f
|
|
return s
|
|
}
|
|
|
|
func (s *MaybeString) Execute(f ExecuteStringFunc) {
|
|
go func(s *MaybeString) {
|
|
str, err := f()
|
|
if err != nil {
|
|
s.failFunc(err)
|
|
} else {
|
|
s.successFunc(str)
|
|
}
|
|
}(s)
|
|
}
|