Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Add utility callback for filtering records by existential flags #4

Open
thisisaaronland opened this issue Nov 16, 2017 · 1 comment

Comments

@thisisaaronland
Copy link
Member

For example, take this which is in the go-whosonfirst-pip-v2 package and make it a high-level shared thingy for use in other packages...

type ApplicationIndexerOptions struct {
        IndexMode         string
        IsWOF             bool
        IncludeDeprecated bool
        IncludeSuperseded bool
        IncludeCeased     bool
        IncludeNotCurrent bool
}

func NewApplicationIndexer(appindex pip.Index, opts ApplicationIndexerOptions) (*index.Indexer, error) {

        cb := func(fh io.Reader, ctx context.Context, args ...interface{}) error {

                var f geojson.Feature

                if opts.IsWOF {

                        ok, err := pip_utils.IsValidRecord(fh, ctx)

                        if err != nil {
                                return err
                        }

                        if !ok {
                                return err
                        }

                        tmp, err := feature.LoadWOFFeatureFromReader(fh)

                        if err != nil {
                                return err
                        }

                        if !opts.IncludeNotCurrent {

                                fl, err := whosonfirst.IsCurrent(f)

                                if err != nil {
                                        return err
                                }

                                if fl.IsTrue() && fl.IsKnown() {
                                        return nil
                                }
                        }
 
                         // and so  on...
@thisisaaronland
Copy link
Member Author

Have a look at:

It might be worth considering the callback-equivalent of io.MultiWriter

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant