Skip to content

Commit

Permalink
ref: vendor lo (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Oct 25, 2024
1 parent 59abc2f commit a2430bf
Show file tree
Hide file tree
Showing 27 changed files with 1,640 additions and 21 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
go.uber.org/mock v0.5.0
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
)

require (
Expand All @@ -30,7 +31,6 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/tools v0.26.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand All @@ -39,7 +39,6 @@ require (
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.1
github.com/samber/lo v1.47.0
github.com/spf13/viper v1.19.0
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
github.com/snivilised/li18ngo v0.1.7 h1:XRYpmP7jSAxzRyg5WH0PViFb9ycWGFcDkQQqd2GsjzQ=
github.com/snivilised/li18ngo v0.1.7/go.mod h1:NVOexqt/aIhnenNPQDqbJchLNte92io87j5o2l+HNqs=
github.com/snivilised/nefilim v0.1.4 h1:bhiENDl/T6ZQO146eF8UnxtXLQenSzEyjwuTeWScImw=
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/cobra-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package assistant
import (
"reflect"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
"github.com/spf13/cobra"

"github.com/snivilised/cobrass/src/assistant/locale"
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sort"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant/locale"
"github.com/snivilised/cobrass/src/internal/third/lo"
)

// AcceptableEnumValues maps values of enum type to an array of
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/internal/lab"
"github.com/snivilised/cobrass/src/internal/third/lo"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/param-set-binder-helpers-auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"regexp"
"time"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant/locale"
"github.com/snivilised/cobrass/src/internal/third/lo"

"github.com/spf13/pflag"
)
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/param-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"reflect"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant/locale"
"github.com/snivilised/cobrass/src/internal/third/lo"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down
2 changes: 1 addition & 1 deletion src/assistant/param-set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok
. "github.com/onsi/gomega" //nolint:revive // gomega ok
"github.com/samber/lo"
"github.com/snivilised/cobrass/src/assistant"
"github.com/snivilised/cobrass/src/internal/lab"
"github.com/snivilised/cobrass/src/internal/third/lo"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion src/clif/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"slices"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
)

var booleans = []string{"true", "false"}
Expand Down
2 changes: 1 addition & 1 deletion src/collections/sorted-keys-map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"cmp"
"slices"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
)

// https://go.dev/blog/comparable
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/content-parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"
)

Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"path/filepath"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/generators/gola"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"
)

Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/gomega-matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"strings"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/generators/gola"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"

. "github.com/onsi/gomega/types" //nolint:revive // gomega ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"cmp"
"slices"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
)

// https://go.dev/blog/comparable
Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/mem-fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"
"testing/fstest"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/lab"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"
)

Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/source-code-container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"text/template"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/generators/gola/internal/collections"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"
)

Expand Down
2 changes: 1 addition & 1 deletion src/generators/gola/source-code-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"path"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/lab"
"github.com/snivilised/cobrass/src/internal/third/lo"
nef "github.com/snivilised/nefilim"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"time"

"github.com/samber/lo"
"github.com/snivilised/cobrass/src/internal/third/lo"
"github.com/snivilised/cobrass/src/assistant/i18n"

"github.com/spf13/pflag"
Expand Down
21 changes: 21 additions & 0 deletions src/internal/third/lo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Samuel Berthe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
138 changes: 138 additions & 0 deletions src/internal/third/lo/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package lo

// MIT License
//
// Copyright (c) 2022 Samuel Berthe

func Ternary[T any](condition bool, ifOutput, elseOutput T) T {
if condition {
return ifOutput
}

return elseOutput
}

func TernaryF[T any](condition bool, ifFunc, elseFunc func() T) T {
if condition {
return ifFunc()
}

return elseFunc()
}

// TernaryE is the same as TernaryF except the functions defined
// must return an error
// func TernaryE[T any](condition bool, ifFunc, elseFunc func() (T, error)) (T, error) {
// if condition {
// return ifFunc()
// }

// return elseFunc()
// }

// type IfElse[T any] struct {
// result T
// done bool
// }

// func If[T any](condition bool, result T) *IfElse[T] {
// if condition {
// return &IfElse[T]{result, true}
// }

// var t T
// return &IfElse[T]{t, false}
// }

// func IfF[T any](condition bool, resultF func() T) *IfElse[T] {
// if condition {
// return &IfElse[T]{resultF(), true}
// }

// var t T
// return &IfElse[T]{t, false}
// }

// func (i *IfElse[T]) ElseIf(condition bool, result T) *IfElse[T] {
// if !i.done && condition {
// i.result = result
// i.done = true
// }

// return i
// }

// func (i *IfElse[T]) ElseIfF(condition bool, resultF func() T) *IfElse[T] {
// if !i.done && condition {
// i.result = resultF()
// i.done = true
// }

// return i
// }

// func (i *IfElse[T]) Else(result T) T {
// if i.done {
// return i.result
// }

// return result
// }

// func (i *IfElse[T]) ElseF(resultF func() T) T {
// if i.done {
// return i.result
// }

// return resultF()
// }

// type SwitchCase[T comparable, R any] struct {
// predicate T
// result R
// done bool
// }

// func Switch[T comparable, R any](predicate T) *SwitchCase[T, R] {
// var result R

// return &SwitchCase[T, R]{
// predicate,
// result,
// false,
// }
// }

// func (s *SwitchCase[T, R]) Case(val T, result R) *SwitchCase[T, R] {
// if !s.done && s.predicate == val {
// s.result = result
// s.done = true
// }

// return s
// }

// func (s *SwitchCase[T, R]) CaseF(val T, cb func() R) *SwitchCase[T, R] {
// if !s.done && s.predicate == val {
// s.result = cb()
// s.done = true
// }

// return s
// }

// func (s *SwitchCase[T, R]) Default(result R) R {
// if !s.done {
// s.result = result
// }

// return s.result
// }

// func (s *SwitchCase[T, R]) DefaultF(cb func() R) R {
// if !s.done {
// s.result = cb()
// }

// return s.result
// }
10 changes: 10 additions & 0 deletions src/internal/third/lo/constraints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lo

// MIT License
//
// Copyright (c) 2022 Samuel Berthe

// Clonable defines a constraint of types having Clone() T method.
type Clonable[T any] interface {
Clone() T
}
Loading

0 comments on commit a2430bf

Please sign in to comment.