Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Apr 11, 2023
1 parent ca54e30 commit c611a0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/arrayx/idx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package arrayx

func SafeIndex[T any](s []T, i int, ifFailed T) T {
if i < 0 || i >= len(s) {
return ifFailed
}
return s[i]
}
2 changes: 1 addition & 1 deletion pkg/maps/clone.go → pkg/mapx/clone.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package maps
package mapx

func Clone[K comparable, V any](m map[K]V) map[K]V {
newM := make(map[K]V, len(m))
Expand Down
7 changes: 7 additions & 0 deletions pkg/stringx/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ func Bool(s string) (bool, error) {
func Ptr(s string) *string {
return &s
}

func AutoPtr(s string) *string {
if s == "" {
return nil
}
return &s
}

0 comments on commit c611a0f

Please sign in to comment.