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

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
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
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement