samvv

samvv

Introducing Toolbelt, your useful little utility companion

Hi there, this is my first post :grin:

I wanted to let you all know of a new library I am creating, called toolbelt. You can find the source here and the docs here.

Toolbelt extends native Elixir modules with extra functionality. A simple use Toolbelt will make those extra functions accessible, while you can still use everything just as usual. Some of the functions it provides: Keyword.is_keyword, Keyword.is_keyword_element, Map.map_deep, Map.map_keys, Map.map_values, Enum.andmap, Enum.ormap, Enum.first, Enum.last, …

The basic aim of this library is to extend the standard Elixir library with some less common but still highly useful functions. The best example is an implementation of Map.map_deep, which allows you to transform all pairs in an arbitrarily-nested map.

It would be really great if you could help with this library, as I am fairly new to Elixir and don’t (yet) know all of the standard ways of doing things. Above that, I might forget of a few useful functions.

There’s still a lot of work on it so if you have any comments or feedback, please let me know.

Regards,
Sam

Most Liked

OvermindDL1

OvermindDL1

Looks cool, your extension style is interesting. :wink:

Few notes:

andmap(enum, callback)
Performs a classical ormap on the given enumerable

s/ormap/andmap/

first(enum)
Takes the first element from the enumerable

There is no ‘first’ element in some enumerables, maybe this should be called pop to pop one off (since enumerables may not have a specified order, like a large map). Or perhaps called one or so?

ormap(enum, callback)
Performs a classical ormap on the given enumerable

Really should document what a classical ormap is, with examples, same with the andmap. :slight_smile:

rest(enum)
Takes the first element from the enumerable

Definitely not the first, and like the first call this wording makes no sense with many types of enumerables, such a pop function should probably return a tuple of one random and whatever is left over. Or maybe call it after_one?

When documenting should probably take the opportunity to write examples, while also making them doctests.

is_keyword_element(val)
Determines if the given value kan be used as a keyword list element

kan is not a word. ^.^
Also it does not detail what properties can make a value a keyword list element, examples would fix this too.
For note:

  def is_keyword_element(val) do
    is_tuple(val) and tuple_size(val)
  end

is wrong. ^.^ For an Elixir style keyword list the spec of a keyword element is {atom(), any()}, for an Erlang style keyword list the spec is any tuple of size 1 or high filled with any() types.

The extra functions on Map look useful, however they sorely need documentation, examples, and doctests. It’s likely possible to reduce the number of these functions to be a bit more generic as well.

MapLike.is_maplike/1 and MapLike.put/3 have no documentation at all. The rest have no examples or doctests.

Good start though, still weary about the extension method done, but eh, need to futz with it to see. ^.^

samvv

samvv

Hi OvermindDL1,

Thank you so much for your reply :smiley: I didn’t notice the mistakes, will fix them immediately.

No 7 I just discovered myself while implementing some more functions :stuck_out_tongue:

Regards,
Sam

samvv

samvv

Just for the record: I’ve dealt with most of the issues, and added some new niceties as well. When reaching 1.0.0, the code should become much more stable and it should be easier to fork :wink:

Where Next?

Popular in Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
mplatts
With HEEX released we decided to start a components library using Tailwind CSS - check it out here: Petal Components. We also have a boi...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10462 141
New
handnot2
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
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10954 107
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
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
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement