tino415
Hello,
recently I started using TypedStruct and also for quite some time I have problem with typos when using structs in elixir, mainly that struct.fiewld_name is not reported during compile time. So I was playing with idea to create plugin for TypedStruct that would generate getter and setter functions for struct. Good thing is, that when I do typo in function name, code don’t compile, another good thing is that it also generate typespecs, so I assume that dialyzer should report when I try to pass wrong type to setter (untested). I used @before_compile and module attributes that TypedStruct is adding to module:
Example:
defmodule Example do
@before_compile TsAccess
use TypedStruct
typedstruct do
field(:name, :string)
end
end
iex> Example.name(%Example{}, "John Doe")
%Example{name: "John Doe"}
iex> Example.name(%Example{name: "John Doe"})
"John Doe"
I’m also thinking to do another library (or as another feature to this one) that would generate lenses
What do you think?
Trending in Announcing
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
I released Doggo, a collection of unstyled Phoenix components.
https://github.com/woylie/doggo
Features
Unstyled Phoenix components....
New
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
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
Hi everyone,
I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LukeWood
Will these throw an error if given a map?
Will these preserve the struct type when setting a value?
If so seems great!
tino415
Yes (it did not, but great idea so I added it :D)
Yes
Thank you for feedback
tino415
Since it is mi first try at doing library for elixir, CR and API critique is welcomed
LukeWood
Exceptional! Thanks, this is awesome!
tino415
Hello again, I just published version 0.5.0 in which typedstruct is not neceseary anymore and also explicit mode was added where you can define getters
explicitly:All macros support also setting of attribute type:
In case of nonexplicit mode without typed struct, types for specs can by set using
@typesmodule attribute:tino415
0.6.0 I also added lenses generator (base on elixir Access module) generated functions looks like:
tino415
After some sleep I realized that I don’t need postfix _lens, so now lenses are just field functions without arguments a.k.a
get_in(example, [Example.name])function with postfix _lens are generated with deprecation warning. Also any other ideas how further improve it? I have several:Feedback is welcomed
OvermindDL1
Ooo I really like how you setup the lenses!
tino415
Released
1.0.0with removed deprecated_lensfunctions and added@docto generated functions