Skip to content

geniusrabbit/goexp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goexp

License Go Report Card Coverage Status Testing Status

The simple builder structures of expression

Condition example

(v1 = 'val1' OR v2 = 100) AND (v3 not in ('v1', 'v2', 'v3') OR v4 > 100)

condition1 := And(
	Extr(
		func(val *filter) *filterV12 {
			return &filterV12{v1: val.v1, v2: val.v2}
		},
		Or(
			Func(func(val *filterV12) bool {
				return val.v1 == "val1"
			}),
			Func(func(val *filterV12) bool {
				return val.v2 == 100
			}),
		),
	),
	Or(
		Not(Func(func(val *filter) bool {
			var arr = []string{"v1", "v2", "v3"}
			for _, v := range arr {
				if v == val.v3 {
					return true
				}
			}
			return false
		})),
		Func(func(val *filter) bool {
			return val.v4 > 100
		}),
	),
)

if condition1.True(&filter{...}) {
  // DO SOMETHING ...
}

Combination of condition expressions

conditionNew := Extr(
  func(ctx any) *filter {
    return &filter{...}
  },
  And(
    condition1,
    Or(
      condition2,
      condition3,
    ),
  ),
)

About

The simple builder structures of expression

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages