ifilter

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: Apache-2.0 Imports: 3 Imported by: 2

README

package ifilter filters a collection of unknown values by a known interface

Quick Start

package main

import (
	"bytes"
	"fmt"
	"github.com/Reasno/ifilter"
	"io"
	"os"
)

func main() {
	var collection = ifilter.Collection{&os.File{}, &bytes.Buffer{}, struct{}{}, nil, 42}
	collection.Filter(func(reader io.Reader) {
		fmt.Printf("%T\n", reader)
	})
	/*
		*os.File
		*bytes.Buffer
	*/
}

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.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option extends and/or modifies the behavior of Filter. Currently no options are available.

Jump to

Keyboard shortcuts

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