# `FactoryMan.Sequence`
[🔗](https://github.com/arcanemachine/factory_man/blob/v0.19.0/lib/factory_man/sequence.ex#L1)

Module for generating sequential values.

Use `FactoryMan.sequence/1`, `FactoryMan.sequence/2`, or `FactoryMan.sequence/3` to generate
sequential values instead of calling this module directly.

## Attribution

This module is adapted from the sequence functionality in
[ExMachina](https://github.com/thoughtbot/ex_machina). The implementation has been copied and
modified to work with FactoryMan.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `reset`

```elixir
@spec reset() :: :ok
```

Clear all sequence counters. The next call starts at `0`, or at its supplied `:start_at` value.

## Example

    FactoryMan.Sequence.next("joe") # "joe0"
    FactoryMan.Sequence.next("joe") # "joe1"

    FactoryMan.Sequence.reset()

    FactoryMan.Sequence.next("joe") # resets so the return value is "joe0"

You can use list as well:

    FactoryMan.Sequence.next("alphabet_sequence", ["A", "B"]) # "A"
    FactoryMan.Sequence.next("alphabet_sequence", ["A", "B"]) # "B"

    FactoryMan.Sequence.reset()

    FactoryMan.Sequence.next("alphabet_sequence", ["A", "B"]) # resets so the return value is "A"

If you want to reset sequences at the beginning of every test, put it in a `setup` block in your
test.

    setup do
      FactoryMan.Sequence.reset()
    end

The counters are shared by every test, including tests that run at the same time, so `reset/0`
also rewinds the sequences that async tests are using. In async tests, reset only the sequence
names that the test uses, with `reset/1`.

# `reset`

```elixir
@spec reset(any()) :: :ok
```

Set the named sequence counters to `0`, creating them if necessary. Other counters keep their
current positions.

## Examples

You can reset a single sequence:

    FactoryMan.Sequence.next(:alphabet, ["A", "B", "C"]) # "A"
    FactoryMan.Sequence.next(:alphabet, ["A", "B", "C"]) # "B"

    FactoryMan.Sequence.reset(:alphabet)

    FactoryMan.Sequence.next(:alphabet, ["A", "B", "C"]) # "A"

You can also reset multiple sequences at once:

    FactoryMan.Sequence.next(:numeric, [1, 2, 3]) # 1
    FactoryMan.Sequence.next(:numeric, [1, 2, 3]) # 2
    FactoryMan.Sequence.next("joe") # "joe0"
    FactoryMan.Sequence.next("joe") # "joe1"

    FactoryMan.Sequence.reset(["joe", :numeric])

    FactoryMan.Sequence.next(:numeric, [1, 2, 3]) # 1
    FactoryMan.Sequence.next("joe") # "joe0"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
