Crowdhailer

Crowdhailer

Creator of Raxx

I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention.

Assuming you have a double function with the spec double(int()) :: {:ok, int()} and safe dividing function. safe_div(int(), int()) :: {:ok, int()} | {:error, term()}.

Ok now can be used to create a pipeline that looks very much like the native pipe operator.

      iex> {:ok, 6} ~>> safe_div(3) ~>> double
      {:ok, 4.0}

      iex> {:ok, 6} ~>> safe_div(0) ~>> double
      {:error, :zero_division}

I have opened a pull request for this new version and pushed a release candidate. Hopefully it’s now interesting to people.

Showing Posts 1 to 10

ibgib

ibgib

Very concise syntax for tagged fluent builder statements!

def instance(identity_ib_gibs, dest_ib, opts) do
  {:ok, identity_ib_gibs}
  ~>> TB.plan("[src]", opts)
  ~>> TB.add_fork("fork1", dest_ib)
  ~>> TB.add_rel8("rel8_2_src", "[plan.src]", ["instance_of"])
  ~>> TB.yo
end

And I’m planning on more, slightly longer factory methods just like these and this helps clean things up very nicely. Thanks! :smile:

Crowdhailer

Crowdhailer OP

Creator of Raxx

Thanks for the feedback. I haven’t really thought about the builder pattern in elixir, I normally have a great map I pass to a single function if need be but it’s certainly a nice usecase and one where you get to ensure that functions behave the way you want.

Crowdhailer

Crowdhailer OP

Creator of Raxx

Version 0.2.0 released.

I will make a 1.0 release soon as there is almost no API to decide on. The one change that I think perhaps should be made is renaming the OK module to Ok so is follows mix patterns for capitalization?

OvermindDL1

OvermindDL1

I’d recommend Ok as well as it is common vernacular now. However, OK is correct as it is short for (what is considered by etymologists(sp?)) Oll Korrekt, a vernacular of “All Correct” popularized in 1840’s New York (told to me by google ^.^). :slight_smile:

So, although I tend to use Ok myself, technically OK is correct. :slight_smile:

Crowdhailer

Crowdhailer OP

Creator of Raxx

Awesome tangential knowledge. I may well have to add some documentation to the effect of recording that.

brainbag

brainbag

Someone wrote a great article about railway programming in Elixir. They used the >>> operator but it’s quite similar!

Here’s the link: Railway Oriented Programming in Elixir

mkunikow

mkunikow

Nice finding. :heartpulse:
I assume this is based on article Railway oriented programming from great F# blog http://fsharpforfunandprofit.com/ :wink:

Robert Brown • 2 years ago
I too read this RoP article and made an Elixir implementation of it. You can find it here: https://github.com/rob-brown/M… Your implementation simulates the behavior described in the article.However, RoP is intended to be built using monads. By using monads, you can use the bind operation with more than just success/failure, ex. maybe monad and state monad.

Crowdhailer

Crowdhailer OP

Creator of Raxx

Would you describe railway programming as a pattern or a technique.

I see that that article gives a bunch of examples on implementing the macros. My life would have been much easier if i had found that first.

Crowdhailer

Crowdhailer OP

Creator of Raxx

Would you have a use for any of the other concepts, such as the tee. I haven’t noticed them missing from my code. I think it might be an 80/20 rule. ~>> gives the vast majority of the benefits and the rest are just minor improvements

brainbag

brainbag

Although I love the concept, I found some issues with the implementation in practice for user errors, which is where this pattern is intended to be used. In particular:

  1. not all functions return the same shape.
    • one of my own functions that returned {:ok, :name, %metadata{}} which wouldn’t fit.
    • some of the Elixir functions I needed didn’t return an error tuple. Map.fetch/2 for example just returns :error.
  2. Although it was nice to break free when an error happened, I found error handling unnecessarily difficult because rather than handling the :error in context, I was doing it somewhere down the line. Often this meant I had to reconstruct context in order to provide a meaningful message to the UI.

To resolve #1, I decided to change how it measured the results and tested either the result == :error || elem(result, 0) == :error, and any other result was just passed through. This worked better for me and allowed for the shapes to be different. It could be expanded to capture more errors, but it still assumes that it would know all error conditions.

Overall, after using it for a while, it felt more like I was using try/catch or GOTO for flow control, which I am not fond of. I found it to basically be just a prettier but less comprehensible/usable version of with.

I still love the idea of a flow chart for flow control, though!

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New

Other Trending Topics Top

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
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
pferriby
Introductory paragraph I’ll be looking for a keen junior or someone that has a couple of years experience in the real world (so you’ve be...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews