Documentation
¶
Overview ¶
package ifilter filters a collection of unknown values by a known interface
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/Reasno/ifilter"
"io"
"os"
)
func main() {
var collection = ifilter.Collection{&os.File{}, &bytes.Buffer{}, struct{}{}, nil, 42, (io.Reader)(nil)}
collection.Filter(func(reader io.Reader) {
fmt.Printf("%T\n", reader)
})
}
Output: *os.File *bytes.Buffer
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection []interface{}
Collection is a slice of unknown interfaces to be processed. It is just an alias of []interface{}, so you can add/remove element to it like you would do to a normal slice.
func (Collection) Filter ¶
func (c Collection) Filter(callback interface{}, Opts ...Option) error
Filter examines every element in the collection and callback with elements that implement the desired interface. The callback argument must be a valid function with the given signature:
func(i I) error
"I" must be a valid interface, such as io.reader or error.
The callback will be fired for every element implementing I. The callback can optionally return an error. If so, the error will be relayed to the return value of Filter, along with any invalid arguments errors raised while filtering.
func (Collection) FilterSlice ¶
func (c Collection) FilterSlice(callback interface{}, Opts ...Option) error
Filter examines every element in the collection and callback with elements that implement the desired interface. The callback argument must be a valid function with the given signature:
func(i []I) error
"I" must be a valid interface, such as io.reader or error.
Callback can optionally return an error. If so, the error will be relayed to the return value of Filter, along with any invalid arguments errors raised while filtering.