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
Great stuff. many thanks @zachdaniel
1
Popular in Questions
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
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
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
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
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
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
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
Other popular topics
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
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
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New







