dbsimmons64

dbsimmons64

Anonymous functions with Spark DSL?

Hi All.

This isn’t really an Ash question but more a Spark question so I hope it is ok posting here.

I’m writing, yet another, admin type library. The library uses a map to describe various entities like input fields or columns in a table (index view). Below is a simplified example

def table() do
  %{
    columns: [
      %{
        name: :first_name,
        icon: %{
          name: "hero-envelope",
          position: :after,
          colour: [&get_icon_colour/1, [:record, :some_other_arg]]
        }
      },
      %{
        name: :last_name,
        icon: [&get_icon/1, [:record]],
        colour: "yellow"
      },
      %{
        name: :age,
        icon: "age-icon"
      }
    ]
  }
end

The nice thing about the above approach is that I can define a key value as a string or a map or even a function (see above for the definition of icon for the three columns).

However, I really like the Spark DSL approach but before I dive into Spark, is the above possible. I was thinking of something like:

columns do
  column :first_name do
    icon do
      name "hero-envelope"
      position :after

      colour do
        function(&get_icon/1)
        args [:record, :some_other_arg]
      end
    end
  end

  column :last_name do
    icon do
      function &get_icon/1
      args [:record]
    end

    colour "yellow"
  end

  column age do
    icon "age-icon"
  end
end

cheers

Dave

Most Liked

dbsimmons64

dbsimmons64

Great stuff. many thanks @zachdaniel

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
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
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement