henriquefernandez

henriquefernandez

A way to increase Elixir projects readability and maintenance based on use cases and interactors , the main goals are:

  • Single Responsability Principle
  • Composability
  • Readability
  • Screaming architecture
  • Enforce inputs and outputs of our project use cases
  • Better errors (know exactly where code fails)
  • Standardization

Showing Posts 1 to 4

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @henriquefernandez this is definitely an interesting idea. I think a part of getting people to adopt something like this is providing examples that speak to more realistic or comprehensive examples. How would this look like with phoenix / ecto? How would this look like with several distinct tables?

henriquefernandez

henriquefernandez OP

Hi @benwilson512, thank you very much for the tip!

I made an improvement in the README and I intend to keep improving over time :grinning:

al2o3cr

al2o3cr

IMO this needs work - the macro declares an input struct for the use case, but in a UseCase.pipe situation the input isn’t actually that shape (it’s the *.Output struct from the preceding step).

AFAIK the style of indirect invocation used here is going to make it really hard for tools like Dialyzer to spot mismatches between inputs and outputs - they’ll only be detected at runtime. Consider enhancing things like pipe to enforce compatibility at compile-time.

Re: UseCase.pipe, the asymmetry in the argument list (struct followed by N atoms) feels weird. It also doesn’t seem particularly friendly to composition; is there a general way to take

UseCase.pipe [%A{arg1: "foo"}, B]

and then pipe the result into a third use case C?

henriquefernandez

henriquefernandez OP

Hi @al2o3cr, thank you for the tips.

IMO this needs work - the macro declares an input struct for the use case, but in a UseCase.pipe situation the input isn’t actually that shape (it’s the *.Output struct from the preceding step).

We can solve it pattern matching the interactor call function to receive its inputs or an another interactor output. In that way we are explicitly declaring that this interactor can be composed with another one in a specific way :slightly_smiling_face:

Despite the ideas of forcing inputs and outputs, I tried to make the library as malleable as possible. We can use it in the way that suits us best.

AFAIK the style of indirect invocation used here is going to make it really hard for tools like Dialyzer to spot mismatches between inputs and outputs - they’ll only be detected at runtime. Consider enhancing things like pipe to enforce compatibility at compile-time.

I will study about it for new versions, thank you.

UseCase.pipe , the asymmetry in the argument list (struct followed by N atoms) feels weird. It also doesn’t seem particularly friendly to composition;

I did an update on it, now we can do that:

%A{name: "Henrique"} 
|> UseCase.pipe [A, B, C]
|> UseCase.pipe [D]

is there a general way to take
UseCase.pipe [%A{arg1: "foo"}, B]
and then pipe the result into a third use case C ?

I don’t know if I understood it very well, but we can do this:

UseCase.pipe [%A{arg1: "foo"}, B, C]

I really appreciate your comments! Thanks!

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews