IvanR
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:
Trending in Announcing
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
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
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
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
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
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
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
@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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Super great work, man. I like the
tagged_tuplelibrary 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 throughuseor a configuration setting? Not critical but I’d like to be able to not inject a custom Elixir syntax in my projects.hauleth
Well, you can just do not use
use TaggedTupleand instead justrequire TaggedTuple.IvanR
I can imagine the situation that the
---operator is to be used somehow else in the project. Let’s see what can be done in regards to optional overriding.thojanssens1
Is it possible to see a snippet demonstrating where TaggedTuple can typically be useful?
BartOtten
I’m not sure about the use case over Records (besides nice helper functions for conversion). To me it seems ‘Tagged Tuple vs Record’ is like ‘Map vs Struct’. Dynamic vs static.
IvanR
Sure.
tagged_tupleis 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 https://thoughtbot.com/blog/better-domain-modeling-in-elixir-with-sum-typesHere is an example of
ShipmentWeightsum type that can be persisted with Ecto.And this is generic Domo/example_avialia/lib/example_avialia/tagged_tuple_ecto_type.ex at master · IvanRublev/Domo · GitHub to do so for any tagged tuple.
thojanssens1
Very interesting article! Thank you