Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1pkg/gamb
go amb (ambiguous) operator implementation
https://github.com/1pkg/gamb
ambiguous go golang operator
Last synced: about 10 hours 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 (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T21:16:26.000Z (over 3 years ago)
- Last Synced: 2024-06-20T10:16:48.489Z (5 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
[![lint](https://github.com/1pkg/gamb/workflows/lint/badge.svg)](https://github.com/1pkg/gamb/actions?query=workflow%3Alint+branch%3Amaster+)
[![build](https://github.com/1pkg/gamb/workflows/build/badge.svg)](https://github.com/1pkg/gamb/actions?query=workflow%3Abuild+branch%3Amaster+)
[![report](https://goreportcard.com/badge/github.com/1pkg/gamb?nocache)](https://goreportcard.com/report/github.com/1pkg/gamb)
[![version](https://img.shields.io/github/go-mod/go-version/1pkg/gamb?nocache)](https://github.com/1pkg/gamb/blob/master/go.mod)
[![license](https://img.shields.io/github/license/1pkg/gamb?nocache)](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.