AshGleam.GleamBridge (ash_gleam v0.4.0)

Copy Markdown

Standalone DSL for bidirectional Elixir↔Gleam function bridging.

Exposes Elixir functions to Gleam (expose) and makes Gleam functions callable from Elixir (consume).

defmodule MyApp.Math do
  use AshGleam.GleamBridge

  gleam do
    consume do
      function :add_in_gleam, :integer do
        argument :a, :integer, allow_nil?: false
        argument :b, :integer, allow_nil?: false

        run &:gleam_module.add/2
      end
    end

    expose do
      function :add_in_elixir, :integer do
        argument :a, :integer, allow_nil?: false
        argument :b, :integer, allow_nil?: false

        run fn a, b -> {:ok, a + b} end
      end
    end
  end
end

Options

  • :extensions (list of module that adopts Spark.Dsl.Extension) - A list of DSL extensions to add to the Spark.Dsl

  • :otp_app (atom/0) - The otp_app to use for any application configurable options

  • :fragments (list of module/0) - Fragments to include in the Spark.Dsl. See the fragments guide for more.