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

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
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
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
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement