commit 3c6675a59ecb342a6c863dffc6532049e112ec59 Author: DEV Date: Fri Mar 8 01:29:21 2024 +0100 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/active.iml b/.idea/active.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/active.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ca5f74a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/core/go.mod b/core/go.mod new file mode 100644 index 0000000..c9dae76 --- /dev/null +++ b/core/go.mod @@ -0,0 +1,3 @@ +module activething.com/go/core + +go 1.22 diff --git a/core/results/bytes.go b/core/results/bytes.go new file mode 100644 index 0000000..77d646e --- /dev/null +++ b/core/results/bytes.go @@ -0,0 +1,89 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name bytes.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package results + +type ( + BytesResult interface { + IsError() bool // GResult implementation + Cause() error // GResult implementation + Success() []byte // GResult implementation + Value() any + } + + BytesSuccess []byte + + BytesError struct{ error } +) + +func TupleBytesSuccess(bytes []byte) ([]byte, error) { + return bytes, nil +} + +func TupleBytesError(err error) ([]byte, error) { + return nil, err +} + +// BytesSuccess -> BytesResult Implementation + +func MakeBytesSuccess(success []byte) BytesSuccess { + return success +} + +func (_ BytesSuccess) IsError() bool { + return false +} + +func (_ BytesSuccess) Cause() error { + return nil +} + +func (s BytesSuccess) Success() []byte { + return s +} + +func (s BytesSuccess) Value() any { + return s +} + +// BytesError -> BytesResult Implementation + +func MakeBytesError(cause error) BytesError { + return BytesError{cause} +} + +func (e BytesError) IsError() bool { + return true +} + +func (e BytesError) Cause() error { + return e.error +} + +func (_ BytesError) Success() []byte { + return nil +} + +func (_ BytesError) Value() any { + return nil +} diff --git a/core/results/g/result.go b/core/results/g/result.go new file mode 100644 index 0000000..cb1a83c --- /dev/null +++ b/core/results/g/result.go @@ -0,0 +1,92 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name result.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package g + +import "activething.com/go/core/results" + +type ( + Result[T any] interface { + results.Result + Success() T + } + + ResultSuccess[T any] struct { + Result T + } + + ResultError[T any] struct { + error + } +) + +func TupleSuccess[T any](res T) (T, error) { + return res, nil +} + +func TupleError[T any](err error) (T, error) { + var r T + return r, err +} + +func MakeSuccess[T any](res T) ResultSuccess[T] { + return ResultSuccess[T]{res} +} + +func (r ResultSuccess[T]) Success() T { + return r.Result +} + +func (r ResultSuccess[T]) Value() any { + return r.Result +} + +func (_ ResultSuccess[T]) IsError() bool { + return false +} + +func (_ ResultSuccess[T]) Cause() error { + return nil +} + +func MakeError[T any](err error) ResultError[T] { + return ResultError[T]{error: err} +} + +func (r ResultError[T]) Success() T { + var zero T + return zero +} + +func (r ResultError[T]) Value() any { + var zero T + return zero +} + +func (_ ResultError[T]) IsError() bool { + return true +} + +func (r ResultError[T]) Cause() error { + return r.error +} diff --git a/core/results/go.mod b/core/results/go.mod new file mode 100644 index 0000000..cfd34c9 --- /dev/null +++ b/core/results/go.mod @@ -0,0 +1,3 @@ +module activething.com/go/core/results + +go 1.22 diff --git a/core/results/int.go b/core/results/int.go new file mode 100644 index 0000000..b9d9166 --- /dev/null +++ b/core/results/int.go @@ -0,0 +1,89 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name int.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package results + +type ( + IntResult interface { + IsError() bool // GResult implementation + Cause() error // GResult implementation + Success() int // GResult implementation + Value() any // GResult implementation + } + + IntSuccess int + + IntError struct{ error } +) + +func TupleIntSuccess(result int) (int, error) { + return result, nil +} + +func TupleIntError(err error) ([]byte, error) { + return nil, err +} + +// IntSuccess -> Result, G.Result Implementation + +func MakeIntSuccess(success int) IntSuccess { + return IntSuccess(success) +} + +func (_ IntSuccess) IsError() bool { + return false +} + +func (_ IntSuccess) Cause() error { + return nil +} + +func (s IntSuccess) Value() any { + return s +} + +func (s IntSuccess) Success() int { + return int(s) +} + +// IntError -> Result, G.Result Implementation + +func MakeIntError(cause error) IntError { + return IntError{cause} +} + +func (e IntError) IsError() bool { + return true +} + +func (e IntError) Cause() error { + return e.error +} + +func (_ IntError) Value() any { + return 0 +} + +func (_ IntError) Success() int { + return 0 +} diff --git a/core/results/result.go b/core/results/result.go new file mode 100644 index 0000000..3391cda --- /dev/null +++ b/core/results/result.go @@ -0,0 +1,32 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name result.go +// Created by DEV +// Modified 08/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package results + +type ( + Result interface { + IsError() bool + Cause() error + Value() any + } +) diff --git a/core/results/string.go b/core/results/string.go new file mode 100644 index 0000000..bc01478 --- /dev/null +++ b/core/results/string.go @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name string.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package results + +type ( + StringResult interface { + IsError() bool // GResult implementation + Cause() error // GResult implementation + Success() any // GResult implementation + Native() string + } + + StringSuccess string + + StringError struct{ error } +) + +func TupleStringSuccess(result string) (string, error) { + return result, nil +} + +func TupleStringError(err error) (string, error) { + return "", err +} + +// StringSuccess -> Result, G.Result Implementation + +func (_ StringSuccess) IsError() bool { + return false +} + +func (_ StringSuccess) Cause() error { + return nil +} + +func (s StringSuccess) Value() any { + return s +} + +func (s StringSuccess) Success() string { + return string(s) +} + +// StringError -> Result, G.Result Implementation + +func MakeStringError(cause error) IntError { + return IntError{cause} +} + +func (e StringError) IsError() bool { + return true +} + +func (e StringError) Cause() error { + return e.error +} + +func (_ StringError) Success() string { + return "" +} + +func (_ StringError) Value() any { + return "" +} diff --git a/core/types/string/active.go b/core/types/string/active.go new file mode 100644 index 0000000..6197cd3 --- /dev/null +++ b/core/types/string/active.go @@ -0,0 +1,30 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name active.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package string + +import "unsafe" + +func ToBytes(source string) []byte { + return unsafe.Slice(unsafe.StringData(source), len(source)) +} diff --git a/core/types/string/strings.go b/core/types/string/strings.go new file mode 100644 index 0000000..aa8fa31 --- /dev/null +++ b/core/types/string/strings.go @@ -0,0 +1,93 @@ +// ------------------------------------------------------------------------ +// Project active +// Active Thing (activething.com) git.activething.com/go +// +// File name strings.go +// Created by DEV +// Modified 07/03/2024 +// +// Copyright 2024 activething.com +// ------------------------------------------------------------------------ +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + +package string + +type Strings []string + +func MakeStrings(size, capacity int) Strings { + return make(Strings, size, capacity) +} + +func (s Strings) Reset() Strings { + if s != nil { + return s[:0] + } + return s +} + +func (s Strings) Has(value string) bool { + return s.Search(value) != -1 +} + +func (s Strings) Search(search string) int { + ln := len(s) + if ln == 0 { + return -1 + } + if ln < 10 { + return s.searchLineal(search) + } + return s.searchBinary(search) +} + +func (s Strings) searchLineal(search string) int { + for x := 0; x < len(s); x++ { + if s[x] == search { + return x + } + } + return -1 +} + +func (s Strings) searchBinary(search string) int { + lf := 0 + rg := len(s) - 1 + for lf <= rg { + md := (lf + rg) / 2 + if s[md] == search { + return md + } else if s[md] < search { + lf = md + 1 + } else { + rg = md - 1 + } + } + return -1 +} + +func (s Strings) Append(value string) Strings { + return append(s, value) +} + +func (s Strings) Len() int { + return len(s) +} + +func (s Strings) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s Strings) Less(i, j int) bool { + return len(s[i]) < len(s[j]) +} diff --git a/go.work b/go.work new file mode 100644 index 0000000..db72f35 --- /dev/null +++ b/go.work @@ -0,0 +1,8 @@ +go 1.22 + +use ( + + ./core + ./core/results + +) \ No newline at end of file