propositions

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

README

Propositions Package

The propositions package provides a set of proposition functions in Go. These functions allow evaluations of various conditions on various types, each function returning either true or false.

Map Propositions

MapContainsKey

Checks if a map contains a specific key.

m := map[string]int{"apple": 1, "banana": 2}
fmt.Println(propositions.MapContainsKey(m, "apple"))  // Output: true
fmt.Println(propositions.MapContainsKey(m, "orange")) // Output: false
MapContainsValue

Checks if a map contains a specific value.

m := map[string]int{"apple": 1, "banana": 2}
fmt.Println(propositions.MapContainsValue(m, 1)) // Output: true
fmt.Println(propositions.MapContainsValue(m, 3)) // Output: false
MapKeyPropositionAny

Checks if any of the keys in a map satisfy a given proposition.

m := map[int]string{1: "apple", 2: "banana"}
p := func(k int) bool { return k > 1 }
fmt.Println(propositions.MapKeyPropositionAny(m, p)) // Output: true
MapKeyPropositionAll

Checks if all of the keys in a map satisfy a given proposition.

m := map[int]string{1: "apple", 2: "banana"}
p := func(k int) bool { return k > 0 }
fmt.Println(propositions.MapKeyPropositionAll(m, p)) // Output: true
MapKeyPropositionNone

Checks if none of the keys in a map satisfy a given proposition.

m := map[int]string{1: "apple", 2: "banana"}
p := func(k int) bool { return k > 2 }
fmt.Println(propositions.MapKeyPropositionNone(m, p)) // Output: true
MapValuePropositionAny

Checks if any of the values in a map satisfy a given proposition.

m := map[string]int{"apple": 1, "banana": 2}
p := func(v int) bool { return v == 2 }
fmt.Println(propositions.MapValuePropositionAny(m, p)) // Output: true
MapValuePropositionAll

Checks if all of the values in a map satisfy a given proposition.

m := map[string]int{"apple": 1, "banana": 2}
p := func(v int) bool { return v > 0 }
fmt.Println(propositions.MapValuePropositionAll(m, p)) // Output: true
MapValuePropositionNone

Checks if none of the values in a map satisfy a given proposition.

m := map[string]int{"apple": 1, "banana": 2}
p := func(v int) bool { return v > 2 }
fmt.Println(propositions.MapValuePropositionNone(m, p)) // Output: true

Slice Propositions

SliceContains

Checks if a slice contains a specific value.

s := []int{1, 2, 3}
fmt.Println(propositions.SliceContains(s, 2))  // Output: true
fmt.Println(propositions.SliceContains(s, 4)) // Output: false
SliceContainsAll

Checks if a slice contains all the specified values.

s := []int{1, 2, 3}
v := []int{1, 2}
fmt.Println(propositions.SliceContainsAll(s, v)) // Output: true
SliceContainsAny

Checks if a slice contains any of the specified values.

s := []int{1, 2, 3}
v := []int{4, 2}
fmt.Println(propositions.SliceContainsAny(s, v)) // Output: true
SliceContainsNone

Checks if a slice contains none of the specified values.

s := []int{1, 2, 3}
v := []int{4, 5}
fmt.Println(propositions.SliceContainsNone(s, v)) // Output: true
SliceAllLessThan

Checks if all the values in the slice are less than the specified value.

s := []int{1, 2, 3}
fmt.Println(propositions.SliceAllLessThan(s, 4)) // Output: true
SliceAllLessThanOrEqualTo

Checks if all the values in the slice are less than or equal to the specified value.

s := []int{1, 2, 3}
fmt.Println(propositions.SliceAllLessThanOrEqualTo(s, 3)) // Output: true
SliceAllGreaterThan

Checks if all the values in the slice are greater than the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAllGreaterThan(s, 3)) // Output: true
SliceAllGreaterThanOrEqualTo

Checks if all the values in the slice are greater than or equal to the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAllGreaterThanOrEqualTo(s, 4)) // Output: true
SliceAnyLessThan

Checks if any of the values in the slice are less than the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAnyLessThan(s, 5)) // Output: true
SliceAnyLessThanOrEqualTo

Checks if any of the values in the slice are less than or equal to the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAnyLessThanOrEqualTo(s, 6)) // Output: true
SliceAnyGreaterThan

Checks if any of the values in the slice are greater than the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAnyGreaterThan(s, 5)) // Output: true
SliceAnyGreaterThanOrEqualTo

Checks if any of the values in the slice are greater than or equal to the specified value.

s := []int{4, 5, 6}
fmt.Println(propositions.SliceAnyGreaterThanOrEqualTo(s, 4)) // Output: true
SlicePropositionNone

Checks if none of the values in the slice satisfy the given proposition.

s := []int{4, 5, 6}
p := func(v int) bool { return v > 6 }
fmt.Println(propositions.SlicePropositionNone(s, p)) // Output: true
SlicePropositionAny

Checks if any of the values in the slice satisfy the given proposition.

s := []int{4, 5, 6}
p := func(v int) bool { return v == 5 }
fmt.Println(propositions.SlicePropositionAny(s, p)) // Output: true
SlicePropositionAll

Checks if all of the values in the slice satisfy the given proposition.

s := []int{4, 5, 6}
p := func(v int) bool { return v > 3 }
fmt.Println(propositions.SlicePropositionAll(s, p)) // Output: true

License

This Source Code Form is subject to the terms of the Apache Public License, version 2.0. If a copy of the APL was not distributed with this file, you can obtain one at https://www.apache.org/licenses/LICENSE-2.0.txt.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapContainsKey

func MapContainsKey[T comparable, U any](m map[T]U, k T) bool

MapContainsKey returns true if the map contains the key.

func MapContainsValue

func MapContainsValue[T comparable, U comparable](m map[T]U, v U) bool

MapContainsValue returns true if the map contains the value.

func MapKeyPropositionAll

func MapKeyPropositionAll[T comparable, U any](m map[T]U, p func(T) bool) bool

MapKeyPropositionAll returns true if all of the keys in the map satisfy the proposition.

func MapKeyPropositionAny

func MapKeyPropositionAny[T comparable, U any](m map[T]U, p func(T) bool) bool

MapKeyPropositionAny returns true if any of the keys in the map satisfy the proposition.

func MapKeyPropositionNone

func MapKeyPropositionNone[T comparable, U any](m map[T]U, p func(T) bool) bool

MapKeyPropositionNone returns true if none of the keys in the map satisfy the proposition.

func MapValuePropositionAll

func MapValuePropositionAll[T comparable, U any](m map[T]U, p func(U) bool) bool

MapValuePropositionAll returns true if all of the values in the map satisfy the proposition.

func MapValuePropositionAny

func MapValuePropositionAny[T comparable, U any](m map[T]U, p func(U) bool) bool

MapValuePropositionAny returns true if any of the values in the map satisfy the proposition.

func MapValuePropositionNone

func MapValuePropositionNone[T comparable, U any](m map[T]U, p func(U) bool) bool

MapvaluePropositionNone returns true if none of the values in the map satisfy the proposition.

func SliceAllGreaterThan

func SliceAllGreaterThan[T cmp.Ordered](s []T, v T) bool

SliceAllGreaterThan returns true if all the values in the slice are greater than the value.

func SliceAllGreaterThanOrEqualTo

func SliceAllGreaterThanOrEqualTo[T cmp.Ordered](s []T, v T) bool

SliceAllGreaterThanOrEqualTo returns true if all the values in the slice are greater than or equal to the value.

func SliceAllLessThan

func SliceAllLessThan[T cmp.Ordered](s []T, v T) bool

SliceAllLessThan returns true if all the values in the slice are less than the value.

func SliceAllLessThanOrEqualTo

func SliceAllLessThanOrEqualTo[T cmp.Ordered](s []T, v T) bool

SliceAllLessThanOrEqualTo returns true if all the values in the slice are less than or equal to the value.

func SliceAnyGreaterThan

func SliceAnyGreaterThan[T cmp.Ordered](s []T, v T) bool

SliceAnyGreaterThan returns true if any of the values in the slice are greater than the value.

func SliceAnyGreaterThanOrEqualTo

func SliceAnyGreaterThanOrEqualTo[T cmp.Ordered](s []T, v T) bool

SliceAnyGreaterThanOrEqualTo returns true if any of the values in the slice are greater than or equal to the value.

func SliceAnyLessThan

func SliceAnyLessThan[T cmp.Ordered](s []T, v T) bool

SliceAnyLessThan returns true if any of the values in the slice are less than the value.

func SliceAnyLessThanOrEqualTo

func SliceAnyLessThanOrEqualTo[T cmp.Ordered](s []T, v T) bool

SliceAnyLessThanOrEqualTo returns true if any of the values in the slice are less than or equal to the value.

func SliceContains

func SliceContains[T cmp.Ordered](s []T, v T) bool

SliceContains returns true if the slice contains the value.

func SliceContainsAll

func SliceContainsAll[T cmp.Ordered](s []T, v []T) bool

SliceContainsAll returns true if the slice contains all the values.

func SliceContainsAny

func SliceContainsAny[T cmp.Ordered](s []T, v []T) bool

SliceContainsAny returns true if the slice contains any of the values.

func SliceContainsNone

func SliceContainsNone[T cmp.Ordered](s []T, v []T) bool

SliceContainsNone returns true if the slice contains none of the values.

func SlicePropositionAll

func SlicePropositionAll[T any](s []T, proposition func(T) bool) bool

SlicePropositionAll returns true if the proposition of all of the values in the slice satisfy the proposition.

func SlicePropositionAny

func SlicePropositionAny[T any](s []T, proposition func(T) bool) bool

SlicePropositionAny returns true if the proposition of any of the values in the slice satisfy the proposition.

func SlicePropositionNone

func SlicePropositionNone[T any](s []T, proposition func(T) bool) bool

SlicePropositionNone returns true if the proposition of none of the values in the slice satisfy the proposition.

Types

This section is empty.

Jump to

Keyboard shortcuts

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