mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: add go playground demo
This commit is contained in:
@@ -139,6 +139,7 @@ func Pipeline[T any](funcs ...func(T) T) func(T) T {
|
||||
// AcceptIf returns another function of the same signature as the apply function but also includes a bool value to indicate success or failure.
|
||||
// A predicate function that takes an argument of type T and returns a bool.
|
||||
// An apply function that also takes an argument of type T and returns a modified value of the same type.
|
||||
// Play: https://go.dev/play/p/XlXHHtzCf7d
|
||||
func AcceptIf[T any](predicate func(T) bool, apply func(T) T) func(T) (T, bool) {
|
||||
if predicate == nil {
|
||||
panic("programming error: predicate must be not nil")
|
||||
|
||||
@@ -2,6 +2,7 @@ package function
|
||||
|
||||
// And returns a composed predicate that represents the logical AND of a list of predicates.
|
||||
// It evaluates to true only if all predicates evaluate to true for the given value.
|
||||
// Play: https://go.dev/play/p/dTBHJMQ0zD2
|
||||
func And[T any](predicates ...func(T) bool) func(T) bool {
|
||||
if len(predicates) < 2 {
|
||||
panic("programming error: predicates count must be at least 2")
|
||||
@@ -18,6 +19,7 @@ func And[T any](predicates ...func(T) bool) func(T) bool {
|
||||
|
||||
// Nand returns a composed predicate that represents the logical NAND of a list of predicates.
|
||||
// It evaluates to true only if all predicates evaluate to false for the given value.
|
||||
// Play: https://go.dev/play/p/Rb-FdNGpgSO
|
||||
func Nand[T any](predicates ...func(T) bool) func(T) bool {
|
||||
if len(predicates) < 2 {
|
||||
panic("programming error: predicates count must be at least 2")
|
||||
@@ -33,6 +35,7 @@ func Nand[T any](predicates ...func(T) bool) func(T) bool {
|
||||
}
|
||||
|
||||
// Negate returns a predicate that represents the logical negation of this predicate.
|
||||
// Play: https://go.dev/play/p/jbI8BtgFnVE
|
||||
func Negate[T any](predicate func(T) bool) func(T) bool {
|
||||
return func(value T) bool {
|
||||
return !predicate(value)
|
||||
@@ -41,6 +44,7 @@ func Negate[T any](predicate func(T) bool) func(T) bool {
|
||||
|
||||
// Or returns a composed predicate that represents the logical OR of a list of predicates.
|
||||
// It evaluates to true if at least one of the predicates evaluates to true for the given value.
|
||||
// Play: https://go.dev/play/p/LitCIsDFNDA
|
||||
func Or[T any](predicates ...func(T) bool) func(T) bool {
|
||||
if len(predicates) < 2 {
|
||||
panic("programming error: predicates count must be at least 2")
|
||||
@@ -57,6 +61,7 @@ func Or[T any](predicates ...func(T) bool) func(T) bool {
|
||||
|
||||
// Nor returns a composed predicate that represents the logical NOR of a list of predicates.
|
||||
// It evaluates to true only if all predicates evaluate to false for the given value.
|
||||
// Play: https://go.dev/play/p/2KdCoBEOq84
|
||||
func Nor[T any](predicates ...func(T) bool) func(T) bool {
|
||||
if len(predicates) < 2 {
|
||||
panic("programming error: predicates count must be at least 2")
|
||||
@@ -73,6 +78,7 @@ func Nor[T any](predicates ...func(T) bool) func(T) bool {
|
||||
|
||||
// Xnor returns a composed predicate that represents the logical XNOR of a list of predicates.
|
||||
// It evaluates to true only if all predicates evaluate to true or false for the given value.
|
||||
// Play: https://go.dev/play/p/FJxko8SFbqc
|
||||
func Xnor[T any](predicates ...func(T) bool) func(T) bool {
|
||||
if len(predicates) < 2 {
|
||||
panic("programming error: predicates count must be at least 2")
|
||||
|
||||
Reference in New Issue
Block a user