https://github.com/1pkg/gamb
go amb (ambiguous) operator implementation
https://github.com/1pkg/gamb
ambiguous go golang operator
Last synced: 2 months ago
JSON representation
go amb (ambiguous) operator implementation
- Host: GitHub
- URL: https://github.com/1pkg/gamb
- Owner: 1pkg
- License: mit
- Created: 2021-04-11T11:32:25.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T21:16:26.000Z (about 4 years ago)
- Last Synced: 2025-01-20T06:20:10.007Z (4 months ago)
- Topics: ambiguous, go, golang, operator
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
# Gamb: go amb (ambiguous) operator implementation
[](https://github.com/1pkg/gamb/actions?query=workflow%3Alint+branch%3Amaster+)
[](https://github.com/1pkg/gamb/actions?query=workflow%3Abuild+branch%3Amaster+)
[](https://goreportcard.com/report/github.com/1pkg/gamb)
[](https://github.com/1pkg/gamb/blob/master/go.mod)
[](LICENSE)`go get -u github.com/1pkg/gamb`
## Details
This package provides generic variadic implemention of [McCarthy's Ambiguous Operator](https://rosettacode.org/wiki/Amb) in go. Gamb exposes three ambiguous functions `Amb` to yield first variable matching ambiguous predicate; `All` to yield all variables matching ambiguous predicate; `Ord` to yield first strict ordered variable matching ambiguous predicate in single pass. Ambiguous predicate is defined as function `func(v ...interface{}) bool` that accepts ambiguous variable sets permutations and check some bolean condition against them.
```go
out := Amb(
func(v ...interface{}) bool {
return v[0].(int)+v[1].(int)-v[2].(int) == 7
}
NewVar(10, 20, 30),
NewVar(1, 2, 3, 5, 10),
NewVar(2, 3, 4),
)
fmt.Println(out) // [10 1 4]
``````go
out := All(
func(v ...interface{}) bool {
return v[0].(int)+v[1].(int)-v[2].(int) == 7
}
NewVar(10, 20, 30),
NewVar(1, 2, 3, 5, 10),
NewVar(2, 3, 4),
)
fmt.Println(out) // [[10 1 4], [10, 2, 3], [10, 3, 2]]
``````go
out := Ord(
func(v ...interface{}) bool {
return v[0].(int)+v[1].(int)-v[2].(int) == 31
}
NewVar(10, 20, 30),
NewVar(1, 2, 3, 5, 10),
NewVar(2, 3, 4),
)
fmt.Println(out) // [30 5 4]
```**Note:** ambiguous operator generally requires some form of backtracking with `n^m` operators, where `n` - size of ambiguous variable and `m` - number of ambiguous variables (for `ord` operator single pass is used reducing complexity to `n`). Therefore ambiguous operator is not efficient on processing big inputs.
## Licence
Gamb is licensed under the MIT License.
See [LICENSE](LICENSE) for the full license text.