smolcatgirl

smolcatgirl

StructCreate, a library to create a struct from a keyword list or a map

Hi,
I am trying to get better at Elixir and I was looking for a reason to make a library. Because writing libraries seem to be a good way to learn Elixir, not just doing code but actually implementing low level tech and seeing what they return. So I found myself wanting to take a map and create a struct from it. The function should also tolerate if any keys are missing or if there are more keys than whats specified. So i wrote this library.
It has a function that takes a keyword list or a map and converts into a struct given a module name.

Here is the link for anyone interested: https://github.com/smolcatgirl/struct_create

I would like any feedback :slight_smile: Thank you!

Most Liked

smolcatgirl

smolcatgirl

What if I change it to use String.to_existing_atom?

smolcatgirl

smolcatgirl

struct/2 fails if I include too many keys. I could filter the keys before but my library does it for me and it works with keyword lists too.

edit: wait it seems like i got it wrong, struct/2 works with this.

ityonemo

ityonemo

Yes. Also, modules with structs define a magic __struct__/0 function that you can use to get a hold of the default struct, bypassing @enforce_keys requirements (use with caution).

Where Next?

Popular in Libraries Top

scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
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
zoltanszogyenyi
Hey everyone :wave: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-source U...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
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
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
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
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
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
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 49522 488
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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

Sub Categories:

We're in Beta

About us Mission Statement