mudasobwa

mudasobwa

Creator of Cure

Blog post, announcing Pyc package. It allows transparent validation across inserted data with Exvalibur, chaining functions in a monadic-like way, and exposes all the keys as local variables inside methods declared with defmethod (without compilation warnings.)

It also reasonably implements Access behaviour for wrapped structs and Collectable protocol with validation.

— https://dev.to/mudasobwa/elixir-structs-on-steroids-5cd9

Showing Posts 1 to 7

OvermindDL1

OvermindDL1

If the struct has more than three fields,
pattern matching in the function head is to be copy-pasted over the whole module or extracted into a cryptic macro.

Yeah, I tend to use the shorter_maps library for that but even it can still get very long and the formatter breaks things up very weird at times… >.>

Even then, although, it quickly becomes hardly maintainable due to unused variables warnings thrown whenever one calls the all-in-one macro and does not use all the variables injected.

You can just do quote generated: true do to silence most warnings (though not variable unused I think?), or in that case can transform the body to add hoisted versions. Even then that won’t work if you need to pass in 2 of that struct in the same head. :slight_smile:

I needed a monadic behaviour there (once any call in the pipe failed, I want the rest transformations to be skipped and the error immediately returned back.)

You really should look at all of expede’s packages on hex.pm. I use a few of them pretty excessively… >.>

guards: %{check_bar: "is_map(bar)"}}]

And reason this is a string instead of just:

guards: %{check_bar: is_map(bar)}}]

Since the use can be a macro anyway, so it can read it straight? :slight_smile:

Looks like an interesting library overall though. :slight_smile:

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey @mudasobwa. It’s always great to see people take on problems.

There’s a few thing about these libraries that would make them more likely to be used by others. The first big one for Exvalibur is making the source code more readily available. The hexdocs don’t link to any source code, and I couldn’t find it with some cursory googling either. I had to create a project, add it as a dep, and then open the deps directory to get a look at it.

The code contains a LOT of Code. function calls. This is almost always a sign that things aren’t quite right. A lot of it is to support the strings which, as @OvermindDL1 notes, is completely unnecessary because of Elixir’s built in macro support.

mudasobwa

mudasobwa OP

Creator of Cure

I doubt I understand. Hexdocs have a built-in support for links to the source and docs are indeed linked to the code.

Also, I would be grateful to see how to use macros to avoid strings there.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Ah, that’s my mistake, the Exvalibur — exvalibur v0.10.0 page looked like the top module doc and I looked for </> and didn’t see it. I see the code now, I wonder why it wasn’t higher on google.

As far as the macros go, it’s a pretty large topic. I’d consider the guides, and the Metaprogramming Elixir book. I’m a little short on time at the moment but I may be able to comment later with more details. The short version is that your Code.string_to_quoted is what the compiler already does. Try using just is_map(val) and see what the input to your function is.

The functions inside Code should basically never be called at runtime. They’re not optimized for it and can lead to a variety of issues.

mudasobwa

mudasobwa OP

Creator of Cure

This is how Exvalibur works now :slight_smile:

I do not remember why exactly I went with binaries, but I am pretty sure it was because I wanted things TBD and I failed to do it properly.

mudasobwa

mudasobwa OP

Creator of Cure

Sure. The users of this package put guards in their config.exs files though.

mudasobwa

mudasobwa OP

Creator of Cure

Recalled. To be used in config.exs. Also, I should support plain guards, thanks.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
quatermain
Hello, I’m sharing my plugin here in forum after some time so it has time to mature and proof yourself. I use Claude Code daily on a pr...
New
gtcode
Aloha gang, There’s a new class of AI model out from TypeSafe. Jev is their flagship model. You can learn about it here: ...
New
LostKobrakai
I’ve recently created a small library phoenix_vite integrating the vite build tooling with phoenix. It provides an igniter.installer t...
New
danschultzer
I needed something like premailer for rails, and after searching, I decided to make an easy-to-use library to handle inline styles and co...
New
kraleppa
If you’ve ever had to debug a BEAM node you know it can be a painful process. Parsing raw data, or dealing with clutter often gets in the...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
CodeSync
Code BEAM Europe 2026 – Call for Talks is Open! We’re excited to announce that Code BEAM Europe 2026 is now open for talk submissions :t...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews