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
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
New
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
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
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto.
pagination
cursor pagination
sorta...
New
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Other Trending Topics
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
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
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 7 of 7 Posts
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