tmbb

tmbb

Implementing Enum for Explorer.Series

I’m working on a data plotting library for Elixir. I don’t want to force people to use Explorer if they don’t want to, especially because for the actual visualization I have to build normal Elixir structures which represent the state and the geometric figures I want to draw. This means I want to accept sometning like plot([1,2,3], [1,2,3]).

However, I’d like to make it very easy to use series as data sources, and the easiest way of being able to use both series and lists is to implement the Enum protocol for series (basically by calling the already existing Series.to_enum/1 function.

Is this ok? This is my first time implementing a protocol for a non-trivial structure not written by me, and because protocol implementations are global, I wonder if that would be a problem. Should I wrap it in something custom such as %DataSource{} and then implement the %DataSource{} protocol for lists, streams and whatever makes sense?

First Post! Switch mode

LostKobrakai

LostKobrakai

Given Explorer doesn’t implement the protocol I’d argue you shouldn’t do so either. There’s a warning about to_enum being an expensive operation, so hiding it being called is imo not a great idea.

My take would be just expecting an enumerable and letting users call Series.to_enum on their own. It’s not like that additional function would make using your library more difficult and the explicitness of the call being present in users code is imo justified due to the importance for performance.

— All posts loaded —

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91561 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
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
juhalehtonen
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
alexslade
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

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement