Skip to content

Commit

Permalink
improvement: add Ash.Generator.next_in_sequence/3
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 18, 2024
1 parent cec5e10 commit 9a2e080
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ash/generator/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ defmodule Ash.Generator do
|> generate_attributes(generators, true, :create)
end

@doc """
Gets the next value for a given sequence identifier.
See `sequence/3` for more.
This is equivalent to `identifier |> Ash.Generator.sequence(fun, sequencer) |> Enum.at(0)`
"""
def next_in_sequence(identifer, fun, sequencer \\ fn i -> (i || -1) + 1 end) do
identifier
|> sequence(fun, sequencer)
|> Enum.at(0)
end

@doc """
Generate globally unique values.
Expand Down

0 comments on commit 9a2e080

Please sign in to comment.