summaryrefslogtreecommitdiff
path: root/predict/predict.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2019-11-14 06:51:44 +0200
committerEyal Posener <[email protected]>2019-11-18 01:05:47 +0200
commit8724aaf18312e54750540a9578e00d61b1c545d8 (patch)
treed3e736b4fb279975bbcc017ae1bad53e454c5773 /predict/predict.go
parent05b68ffc813dd10c420993cb1cf927b346c057b8 (diff)
V2
Diffstat (limited to 'predict/predict.go')
-rw-r--r--predict/predict.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/predict/predict.go b/predict/predict.go
new file mode 100644
index 0000000..f4d5bb7
--- /dev/null
+++ b/predict/predict.go
@@ -0,0 +1,34 @@
+// Package predict provides helper functions for completion predictors.
+package predict
+
+import "github.com/posener/complete"
+
+// Set predicts a set of predefined values.
+type Set []string
+
+func (p Set) Predict(_ string) (options []string) {
+ return p
+}
+
+var (
+ // Something is used to indicate that does not completes somthing. Such that other prediction
+ // wont be applied.
+ Something = Set{""}
+
+ // Nothing is used to indicate that does not completes anything.
+ Nothing = Set{}
+)
+
+// Or unions prediction functions, so that the result predication is the union of their
+// predications.
+func Or(ps ...complete.Predictor) complete.Predictor {
+ return complete.PredictFunc(func(prefix string) (options []string) {
+ for _, p := range ps {
+ if p == nil {
+ continue
+ }
+ options = append(options, p.Predict(prefix)...)
+ }
+ return
+ })
+}