domain

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package domain provides core interface definitions and domain types for the conch stream processing library. This package establishes the fundamental contracts and abstractions that enable type-safe stream processing.

Goals: - Define clear interfaces for processable elements and processors. - Establish type-safe contracts for cache operations. - Provide fundamental types for stream processing pipelines.

Design Philosophy: The domain package follows the principle of separating interface definitions from implementation details. It defines what operations are possible without dictating how they should be implemented. This allows for multiple implementations while maintaining type safety and clear contracts.

Key interfaces include: - Processable: Elements that can be processed in a stream pipeline. - Cache: Generic caching interface for stream processing optimization. - Hashable: Elements that can be hashed for caching and indexing.

Usage Patterns: - Implement Processable for stream elements that need processing. - Use Cache interface for implementing caching strategies. - Implement Hashable for elements that need to be cached or indexed.

Example:

package main

import (

"context"
"fmt"
"github.com/byte4ever/conch/domain"

)

type MyProcessable struct {
    param  string
    result string
    err    error
}

func (p *MyProcessable) GetParam() string { return p.param } func (p *MyProcessable) SetValue(v string) { p.result = v; p.err = nil } func (p *MyProcessable) GetValue() string { return p.result } func (p *MyProcessable) SetError(e error) { p.err = e; p.result = "" } func (p *MyProcessable) GetError() error { return p.err }

func exampleProcessor(ctx context.Context, elem *MyProcessable) {
    // Process the element
    result := "processed: " + elem.GetParam()
    elem.SetValue(result)
}
func main() {
    ctx := context.Background()
    elem := &MyProcessable{param: "test"}

    exampleProcessor(ctx, elem)

    fmt.Println(elem.GetValue())
}
Example

Example demonstrates the usage of the Processable interface.

package main

import (
	"context"
	"fmt"
)

// MyProcessable implements the Processable interface for demonstration.
type MyProcessable struct {
	param  string
	result string
	err    error
}

func (p *MyProcessable) GetParam() string  { return p.param }
func (p *MyProcessable) SetValue(v string) { p.result = v; p.err = nil }
func (p *MyProcessable) GetValue() string  { return p.result }
func (p *MyProcessable) SetError(e error)  { p.err = e; p.result = "" }
func (p *MyProcessable) GetError() error   { return p.err }

// Example demonstrates the usage of the Processable interface.
func main() {
	ctx := context.Background()
	elem := &MyProcessable{param: "test"}

	// Define a processor function
	processor := func(ctx context.Context, elem *MyProcessable) {
		// Process the element
		result := "processed: " + elem.GetParam()
		elem.SetValue(result)
	}

	// Apply the processor
	processor(ctx, elem)

	// Output the result
	fmt.Println(elem.GetValue())

}
Output:
processed: test

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[P Hashable, R any] interface {
	Get(ctx context.Context, key P) (R, bool)
	Store(ctx context.Context, key P, value R)
}

type Hashable

type Hashable interface {
	Hash() Key
}

type Hashable2

type Hashable2[T any] interface {
	Hash() Key
	SetValue(v T)
}

type Key

type Key struct {
	A, B uint64
}

Key represents a composite of two 64-bit unsigned integers.

func (Key) Values

func (k Key) Values() (uint64, uint64)

Values returns the two uint64 components of the Key: A and B.

type Processable

type Processable[Param any, Result any] interface {
	GetParam() Param
	SetValue(r Result)
	GetValue() Result
	SetError(e error)
	GetError() error
}

type ProcessorFunc

type ProcessorFunc[T Processable[Param, Result], Param any, Result any] func(
	ctx context.Context,
	elem T,
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL