func (s *Sequence) Next() (uint64, error) {
	s.current += s.increment
	if s.current < s.minvalue {
		return 0, errors.New("reached minimum bound of the sequence")
	}
	if s.current > s.maxvalue {
		return 0, errors.New("reached maximum bound of sequence")
	}
	return s.current, nil
}
Next updates the state of the Sequence and return the next item in the
sequence. It will return an error if either the minimum or the maximal
value has been reached.
package sequence
import (
	"encoding/json"
	"errors"
	"fmt"
)
const maxuint64 = ^uint64(0) - 1
const MinimumBound = 1
const MaximumBound = maxuint64
type Incrementer interface {
	Init(params ...uint64) error  
	Next() (uint64, error)        
	Restart() error               
	Current() (uint64, error)     
	IsStarted() bool              
	String() string               
	Load(data []byte) error       
	Dump() ([]byte, error)        
}
type Sequence struct {
	current     uint64  
	increment   uint64  
	minvalue    uint64  
	maxvalue    uint64  
	initialized bool    
}
func New(params ...uint64) (*Sequence, error) {
	seq := new(Sequence)
	err := seq.Init(params...)
	return seq, err
}
func (s *Sequence) Init(params ...uint64) error {
	if s.initialized {
		return errors.New("cannot re-initialize a sequence object")
	}
	if len(params) == 0 {
		s.increment = 1
		s.minvalue = MinimumBound
		s.maxvalue = MaximumBound
	}
	if len(params) == 1 {
		if params[0] < MinimumBound {
			return errors.New("must specify a maximal value greater than 0")
		}
		s.increment = 1
		s.minvalue = MinimumBound
		s.maxvalue = params[0]
	}
	if len(params) == 2 {
		if params[1] < params[0] {
			return errors.New("for a positive increment, the maximum value must be greater than or equal to the minimum value")
		}
		if params[0] < MinimumBound || params[1] > MaximumBound {
			return errors.New("part of the range is out of bounds for positive increment")
		}
		s.increment = 1
		s.minvalue = params[0]
		s.maxvalue = params[1]
	}
	if len(params) == 3 {
		if params[2] == 0 {
			return errors.New("must have a non-zero step to increment by")
		}
		if params[2] < 0 {
			if params[0] < params[1] {
				return errors.New("for a negative increment, the first value must be greater than or equal to the second value")
			}
			if params[1] < MinimumBound || params[0] > MaximumBound {
				return errors.New("part of the range is out of bounds for negative increment")
			}
		} else {
			if params[1] < params[0] {
				return errors.New("for a positive increment, the second value must be greater than or equal to the first value")
			}
			if params[0] < MinimumBound || params[1] > MaximumBound {
				return errors.New("part of the range is out of bounds for positive increment")
			}
		}
		s.increment = params[2]
		s.minvalue = params[0]
		s.maxvalue = params[1]
	}
	if len(params) > 3 {
		return errors.New("too many arguments specified")
	}
	if int(s.minvalue)-int(s.increment) < 0 {
		return errors.New("the minimum value must be less than or equal to the step")
	}
	s.current = s.minvalue - s.increment
	s.initialized = true
	return nil
}