IvanR

IvanR

TaggedTuple

A library to work with tagged tuples.
Provides functions to work with chains of tags for nested tuples.

Some of the supported operations are: add/remove tag chain to a core value, converting a tuple to list or to map and back. The latter one is useful for converting tuples to/from JSON representation.

iex> use TaggedTuple
...> core_value = 12
...> :tag --- core_value
{:tag, 12}
...> tagged_tuple = :a --- :tag --- :chain --- core_value
{:a, {:tag, {:chain, 12}}}
...> match?(:a --- :tag --- _tail, tagged_tuple)
true

iex> {chain, value} = TaggedTuple.split({:a, {:tag, {:chain, 2}}})
...> chain == {:a, {:tag, :chain}}
...> value == 2
iex> TaggedTuple.tag(2, {:a, {:tag, :chain}})
{:a, {:tag, {:chain, 2}}}

iex> TaggedTuple.to_map({:a, {:tag, {:chain, 2}}})
%{a: %{tag: %{chain: 2}}}
iex> TaggedTuple.from_map(%{a: %{tag: %{chain: 2}}})
{:a, {:tag, {:chain, 2}}}

More information here:

Most Liked

dimitarvp

dimitarvp

Super great work, man. I like the tagged_tuple library a lot, already used it in a small hobby project as a test!

One thing that might be worth mentioning: would you consider making the custom syntax (the 3 dashes: ---) optional and injectable through use or a configuration setting? Not critical but I’d like to be able to not inject a custom Elixir syntax in my projects.

IvanR

IvanR

Sure. tagged_tuple is to operate with sum types. Which are one of the ways to making impossible states impossible in the app. Here is a good article about these Better domain modeling in Elixir with sum types

Here is an example of ShipmentWeight sum type that can be persisted with Ecto.
And this is generic Domo/tagged_tuple_ecto_type.ex at master · IvanRublev/Domo · GitHub to do so for any tagged tuple.

hauleth

hauleth

Well, you can just do not use use TaggedTuple and instead just require TaggedTuple.

thojanssens1

thojanssens1

Is it possible to see a snippet demonstrating where TaggedTuple can typically be useful?

Where Next?

Popular in Libraries Top

kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
574 16576 179
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. [demo] The distributed characteristics of Elixir and the low memory foo...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
engineeringdept
I’ve just released the first version of Snap, an Elasticsearch client. It borrows ideas about application structure and process managemen...
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
Brian
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
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
lanycrost
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

Sub Categories:

We're in Beta

About us Mission Statement