github.com/pachyderm/pachyderm@v1.13.4/src/server/pkg/storage/fileset/transforms.go (about) 1 package fileset 2 3 import ( 4 "context" 5 "io" 6 7 "github.com/pachyderm/pachyderm/src/server/pkg/storage/fileset/index" 8 ) 9 10 var _ FileSet = &indexFilter{} 11 12 type indexFilter struct { 13 pred func(idx *index.Index) bool 14 x FileSet 15 } 16 17 // NewIndexFilter filters x using pred 18 func NewIndexFilter(x FileSet, pred func(idx *index.Index) bool) FileSet { 19 return &indexFilter{x: x, pred: pred} 20 } 21 22 func (fil *indexFilter) Iterate(ctx context.Context, cb func(File) error, _ ...bool) error { 23 return fil.x.Iterate(ctx, func(fr File) error { 24 idx := fr.Index() 25 if fil.pred(idx) { 26 return cb(fr) 27 } 28 return nil 29 }) 30 } 31 32 var _ FileSet = &indexMapper{} 33 34 type indexMapper struct { 35 fn func(idx *index.Index) *index.Index 36 x FileSet 37 } 38 39 // NewIndexMapper performs a map operation on the index entries of the files in the file set. 40 func NewIndexMapper(x FileSet, fn func(*index.Index) *index.Index) FileSet { 41 return &indexMapper{x: x, fn: fn} 42 } 43 44 func (im *indexMapper) Iterate(ctx context.Context, cb func(File) error, _ ...bool) error { 45 return im.x.Iterate(ctx, func(fr File) error { 46 y := im.fn(fr.Index()) 47 return cb(&indexMap{ 48 idx: y, 49 inner: fr, 50 }) 51 }) 52 } 53 54 var _ File = &indexMap{} 55 56 type indexMap struct { 57 idx *index.Index 58 inner File 59 } 60 61 func (im *indexMap) Index() *index.Index { 62 return im.idx 63 } 64 65 func (im *indexMap) Content(w io.Writer) error { 66 return im.inner.Content(w) 67 }