Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extractor ¶
type Extractor[K comparable, V any] interface { // ByValue filters the values of the collection by their values. ByValue(condition func(V) bool) Extractor[K, V] // ByKey filters the values of the collection by their keys. ByKey(condition func(K) bool) Extractor[K, V] // ByKeyAndValue filters the values of the collection by their keys and values. ByKeyAndValue(condition func(K, V) bool) Extractor[K, V] // Values returns a sequence of values. Values() iter.Seq[V] }
Extractor provides features to extract values from a collection.
func FromMap ¶
func FromMap[K comparable, V any](m map[K]V) Extractor[K, V]
FromMap returns Extractor for a map.
type MapExtractor ¶
type MapExtractor[K comparable, V any] struct { // contains filtered or unexported fields }
MapExtractor is implementation of Extractor for map.
func (MapExtractor[K, V]) ByKey ¶
func (x MapExtractor[K, V]) ByKey(condition func(K) bool) Extractor[K, V]
ByKey See: Extractor.ByKey
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" "strings" ) func main() { m := map[string]string{"language": "gopher", "design pattern": "iterator", "implementation": "range over func"} xt := xtract.FromMap(m).ByKey(func(k string) bool { return strings.Contains(k, " ") }) for v := range xt.Values() { fmt.Println(v) } }
Output: iterator
func (MapExtractor[K, V]) ByKeyAndValue ¶
func (x MapExtractor[K, V]) ByKeyAndValue(condition func(K, V) bool) Extractor[K, V]
ByKeyAndValue See: Extractor.ByKeyAndValue
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" "strings" ) func main() { m := map[string]string{"language": "gopher", "design pattern": "iterator", "implementation": "range over func"} xt := xtract.FromMap(m).ByKeyAndValue(func(k, v string) bool { return strings.Contains(k, "e") && len(v) < 8 }) for v := range xt.Values() { fmt.Println(v) } }
Output: gopher
func (MapExtractor[K, V]) ByValue ¶
func (x MapExtractor[K, V]) ByValue(condition func(V) bool) Extractor[K, V]
ByValue See: Extractor.ByValue
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" ) func main() { m := map[string]string{"language": "gopher", "design pattern": "iterator", "implementation": "range over func"} xt := xtract.FromMap(m).ByValue(func(v string) bool { return len(v) < 8 }) for v := range xt.Values() { fmt.Println(v) } }
Output: gopher
func (MapExtractor[K, V]) Values ¶ added in v0.2.0
func (x MapExtractor[K, V]) Values() iter.Seq[V]
Values See: Extractor.Values
type SliceExtractor ¶
type SliceExtractor[V any] struct { // contains filtered or unexported fields }
SliceExtractor is implementation of Extractor for slice.
func (*SliceExtractor[V]) ByKey ¶
func (x *SliceExtractor[V]) ByKey(condition func(int) bool) Extractor[int, V]
ByKey See: Extractor.ByKey
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" ) func main() { s := []string{"gopher", "iterator", "range over func"} xt := xtract.FromSlice(s).ByKey(func(i int) bool { return i > 0 }) for v := range xt.Values() { fmt.Println(v) } }
Output: iterator range over func
func (*SliceExtractor[V]) ByKeyAndValue ¶
func (x *SliceExtractor[V]) ByKeyAndValue(condition func(int, V) bool) Extractor[int, V]
ByKeyAndValue See: Extractor.ByKeyAndValue
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" ) func main() { s := []string{"gopher", "iterator", "range over func"} xt := xtract.FromSlice(s).ByKeyAndValue(func(i int, v string) bool { return i > 1 && len(v) > 6 }) for v := range xt.Values() { fmt.Println(v) } }
Output: range over func
func (*SliceExtractor[V]) ByValue ¶
func (x *SliceExtractor[V]) ByValue(condition func(V) bool) Extractor[int, V]
ByValue See: Extractor.ByValue
Example ¶
package main import ( "fmt" "github.com/miyamo2/xtract" ) func main() { s := []string{"gopher", "iterator", "range over func"} xt := xtract.FromSlice(s).ByValue(func(v string) bool { return len(v) < 9 }) for v := range xt.Values() { fmt.Println(v) } }
Output: gopher iterator
func (*SliceExtractor[V]) Values ¶ added in v0.2.0
func (x *SliceExtractor[V]) Values() iter.Seq[V]
Values See: Extractor.Values
Click to show internal directories.
Click to hide internal directories.