IterateCasts iterates over all casts in the collection.
(ctx context.Context, callback func(c Cast) (stop bool, err error))
| 533 | |
| 534 | // IterateCasts iterates over all casts in the collection. |
| 535 | func (pgc *Collection) IterateCasts(ctx context.Context, callback func(c Cast) (stop bool, err error)) error { |
| 536 | for _, cast := range builtInCasts { |
| 537 | stop, err := callback(cast) |
| 538 | if err != nil { |
| 539 | return err |
| 540 | } else if stop { |
| 541 | return nil |
| 542 | } |
| 543 | } |
| 544 | return pgc.underlyingMap.IterAll(ctx, func(_ string, v hash.Hash) error { |
| 545 | data, err := pgc.ns.ReadBytes(ctx, v) |
| 546 | if err != nil { |
| 547 | return err |
| 548 | } |
| 549 | c, err := DeserializeCast(ctx, data) |
| 550 | if err != nil { |
| 551 | return err |
| 552 | } |
| 553 | stop, err := callback(c) |
| 554 | if err != nil { |
| 555 | return err |
| 556 | } else if stop { |
| 557 | return io.EOF |
| 558 | } else { |
| 559 | return nil |
| 560 | } |
| 561 | }) |
| 562 | } |
| 563 | |
| 564 | // Clone returns a new *Collection with the same contents as the original. |
| 565 | func (pgc *Collection) Clone(ctx context.Context) *Collection { |
no test coverage detected