Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add transition_to!/3~4 #90

Open
kyleboe opened this issue Apr 14, 2024 · 0 comments
Open

Feature: Add transition_to!/3~4 #90

kyleboe opened this issue Apr 14, 2024 · 0 comments

Comments

@kyleboe
Copy link

kyleboe commented Apr 14, 2024

Similar to other ! suffixed functions, the thought would be to either return the transformed struct or raise an error. The goal of this change would be to allow the transition_to! call to be chained in a pipeline.

Given:

defmodule MyStateMachine do
  use Machinery,
    states: ~w(pending completed),
    transitions: %{"pending" => ["completed"]}
end

defmodule MyStruct do
  defstruct [:state]
end

The spec for the function(s) may look something like this:

Machinery.transition_to!(%MyStruct{state: "pending"}, MyStateMachine, "completed")
# %MyStruct{state: "completed"}

Machinery.transition_to!(%MyStruct{state: "completed"}, MyStateMachine, "pending")
# raise Machinery.Errors.UndeclaredTransition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant