Qqwy

Qqwy

TypeCheck Core Team

How to use Inspect.Algebra?

As some of you might now, I am creating a Multi User Dungeon (a text-based multiplayer game) in Elixir. This is mostly a hobby project, to learn what a non-trivial project in Elixir will look like, and do’s and don’t when an Elixir project grows in size.

The text that is generated in the game is sent over a simple TCP connection to the telnet shells of connected clients. What I would like to do, is to format this text, so lines break nicely, instead of cutting words in half.

I think the Inspect.Algebra module is useful for this, as I presume that this is what Elixir uses underwater to print the pretty-printed documentation whenever you use h Modulename in IEx.

However, I am a bit stumped on how to use it properly. Can someone explain how I can use it to generate line-breaks from an iodata string?

Most Liked

bbense

bbense

Inspect.Algebra is a set of tools for implementing the Inspect protocol for your data types.

Probably the best place to figure out how to use it is in the Elixir source code itself.

Look at the defimpl Inspect for the various data types to get examples.

gregvaughn

gregvaughn

I toyed with it once briefly, but I’m pretty sure the APIs have changed since then. The best example I know of is in the Programming Elixir book, and now that I review it, it’s not as extensive as I recall.

bbense

bbense

BTW, digging through the code of Inspect is how I actually really understood protocols and I “borrowed” much of the structure of phst_transform from the Inspect protocol.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement