mudasobwa

mudasobwa

Creator of Cure

Blogged about the motivation and reasoning behind my idea to create yet another FSM library. Long story short: I did it in a proper way :slight_smile:

Finitomata :: The Proper FSM for Elixir

Showing Posts 18 to 9

ivanhercaz

ivanhercaz

Thank you very much, @mudasobwa! I must be going blind because I really didn’t see the examples directory in Finitomata’s repository :sweat_smile: . Really useful example.

mudasobwa

mudasobwa OP

Creator of Cure

There is https://github.com/am-kantox/finitomata/tree/main/examples/ecto_intergation non-official take on integration with ecto (which would not be the best implementation, but still.)
Aside from that, all other real-world examples I have I cannot actually share. I will try to come up with a better more sophisticated example, thanks.

ivanhercaz

ivanhercaz

First, really great package, @mudasobwa. Easy to use and intuitive. Thank you for this contribution to the Elixir ecosystem.

Some days ago I tried to implemented a FSM to manage the setup of an application, but then I realized that maybe is not the proper use case.

Aside from the examples given in Finitomata’s documentation, have you got some application example with Finitomata implemented? Just to learn until I have the necessary time to implement some ideas I have.

Thanks in advance!

KristerV

KristerV

these examples are great. this opens up a whole new section in my head. thanks!

mudasobwa

mudasobwa OP

Creator of Cure

Great! But in my understanding, the textual representation is easier to grasp and it produces a diagram in docs for free.

Oliver

Oliver

This reminds me of the FSM framework I wrote for usage in my own project.

I did however not resort to parsing a description string, I used some macros instead.

defmacro __using__(_opts) do
  quote do
    Module.register_attribute(__MODULE__, :transitions, accumulate: true)

    import     unquote(__MODULE__)

    # ensure our additional functions are added only right before compilation
    # after all module attribute values have been fully determined
    @before_compile unquote(__MODULE__)
  end
end

defmacro __before_compile__(_env) do
  quote do
    def transitions, do: @transitions
  end
end

defmacro transition(list) do
 # [...] omitted some checks for required fields for example 

  quote do
    @transitions unquote(list)
  end
end

You can then add transitions like this:

  use # "<module name>"

  transition(state: :idle, in: :start,    next: :wait)
  transition(state: :wait, in: :continue, end:  :pass)
  transition(state: :end,  in: :finish)

I ended up supporting waiting for different incoming messages, a join, end states, and “guard functions” that can further refine if a transition is taken.

The resulting list of transitions then ends up in a module attribute I can read and process.

(The part of handler functions or callbacks is not shown as it is not specific to describing the transition table. I defaulted to handle/2 as a default function for incoming functions, and allowed a user-defined handler name if needed that could be defined differently for every single transition.)

mudasobwa

mudasobwa OP

Creator of Cure

FWIW, I have implemented mermaid support. This is how the documentation for the generated module looks when mermaid syntax is used. Kudos and many thanks!

mudasobwa

mudasobwa OP

Creator of Cure

Wow. Thanks! Somehow I missed this possibility. Will surely support it alongside PlantUML. BTW, the compile-time check is already implemented in the library during definition parsing.

ityonemo

ityonemo

I think there’s probably a smart way to use mermaid (which is easy to ship with exdoc now) instead. Plantuml is kind of tricky syntax and while it’s open source, it’s really hard to install and put into a pipeline :P. Though at work I forced the database tables to be plantuml documented by creating a compile-time check.

mudasobwa

mudasobwa OP

Creator of Cure

Turned out, I’ve already written about another real example: webhooks.

Where Next? Top

Trending in Blog Posts Top

bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
pckrishnadas88
Hey everyone! :waving_hand: I’ve published Part 7 of the Building Distributed Systems in Elixir series, where we build core distributed ...
New
zorn
An educational side project in Elixir, Phoenix, and Tauri. I share what I learned while wiring Automerge into the BEAM, including how I s...
New
nathanl
Process labels are useful for visualization and debugging. Here’s why you should use them.
New
abreujp
New article: Elixir Project Structure — From mix new to a Growing Codebase I’ve published a new article in my Elixir learning series on d...
New
andreasronge
What happens if you design tools for LLMs instead of letting LLM use human tools ? Wrote a blog on why and what that enables. As I see ...
New
mudasobwa
Somewhere, right now, a senior engineer is on the verge of a nervous breakdown because his company will not let him switch from Claude to...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews