← Library BooleanDeterministic

BoolNotOp

Inverts a boolean value — returns NOT Value.

Inputs

FieldTypeDescription
Value*boolBoolean to invert

Outputs

FieldTypeDescription
ResultboolInverted value

Typical Use Cases

  • Inverting a predicate result
  • NOT gate in a logic chain
  • Routing on the absence of a condition

Complete Runnable Example

Inverts a spam flag so downstream nodes can act on clean messages.

main.go
package main

import (
	"context"
	"encoding/json"
	"log"
	"os"
	"time"

	"github.com/akennis/sparsi-go/library"
	_ "github.com/akennis/dagor/operator/builtin"

	"github.com/panjf2000/ants/v2"
	"github.com/akennis/dagor"
	"github.com/akennis/dagor/graph"
)

func main() {
	isSpam := true

	library.RegisterConst("spam_val", isSpam)

	g, err := graph.NewBuilder("bool_not_demo").
		Vertex("src").Op("spam_val").
		Output("Result", "spam_wire").

		Vertex("invert").Op("BoolNotOp").
		Input("Value", "spam_wire").
		Output("Result", "not_spam_wire").

		Build()
	if err != nil {
		log.Fatalf("build: %v", err)
	}

	pool, err := ants.NewPool(4)
	if err != nil {
		log.Fatalf("pool: %v", err)
	}
	defer pool.Release()

	eng, err := dagor.NewEngine(g, pool)
	if err != nil {
		log.Fatalf("engine: %v", err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	if err := eng.Run(ctx); err != nil {
		log.Fatalf("run: %v", err)
	}

	out := map[string]any{
		"is_spam": isSpam,
	}
	if raw, ok := eng.GetOutput("not_spam_wire"); ok {
		out["is_not_spam"] = *raw.(*bool)
	}

	enc := json.NewEncoder(os.Stdout)
	enc.SetIndent("", "  ")
	enc.Encode(out)
}