http urls monitor.

immutable.go 795B

1234567891011121314151617181920212223242526272829
  1. package immutable
  2. // Immutable represents an immutable chain that, if passed to FastForward,
  3. // applies Fn() to every element of a chain, the first element of this chain is
  4. // represented by Base().
  5. type Immutable interface {
  6. // Prev is the previous element on a chain.
  7. Prev() Immutable
  8. // Fn a function that is able to modify the passed element.
  9. Fn(interface{}) error
  10. // Base is the first element on a chain, there's no previous element before
  11. // the Base element.
  12. Base() interface{}
  13. }
  14. // FastForward applies all Fn methods in order on the given new Base.
  15. func FastForward(curr Immutable) (interface{}, error) {
  16. prev := curr.Prev()
  17. if prev == nil {
  18. return curr.Base(), nil
  19. }
  20. in, err := FastForward(prev)
  21. if err != nil {
  22. return nil, err
  23. }
  24. err = curr.Fn(in)
  25. return in, err
  26. }