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 Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
mathieuprog
Hello :wave: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First and fore...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Th...
New
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
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
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Sub Categories:

We're in Beta

About us Mission Statement