shahryarjb

shahryarjb

Cannot invoke remote function Regex.match?/2 inside guard

Hello, I wanted to create custom guard like this , but I have an error:

cannot invoke remote function Regex.match?/2 inside guard

guard:

defmodule TrangellHtmlSite.Blog.GuardCustom do
  defmacro amount_cheaker(number) do
    quote do
      Regex.match?(~r/^([+-]?[1-9]\d*|0)$/, unquote(number))
    end
  end
end


---

defmodule TrangellHtmlSiteWeb.PayController do
  use TrangellHtmlSiteWeb, :controller
  alias TrangellHtmlSite.Blog.ZarinPal
  import TrangellHtmlSite.Blog.GuardCustom, only: [amount_cheaker: 1]

  def check_pay(conn, %{"amount" => amount}) when amount_cheaker(amount) do
    conn = put_session(conn, :amount, amount)
    %{"{http://zarinpal.com/}Authority" => authority, "{http://zarinpal.com/}Status" =>  status} = ZarinPal.zarinpal_send(amount)
    check_status_send(conn, status, authority)
  end
end

How do I fix this?

Most Liked

radarjones

radarjones

You might want to read this.

https://hexdocs.pm/elixir/guards.html

NobbZ

NobbZ

You can’t. This is a limitation of the BEAM.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New

We're in Beta

About us Mission Statement