You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since upstream TypedStruct 0.2.0 now supports plugins, Contructor could be a plugin. This way, it would be composable with other TypedStruct plugins.
The API would look like:
defmoduleConstructorExampleUserdouseTypedStruct# Use the “standard” typedstruct macro.typedstructdopluginConstructor# Register Constructor as a plugin. Code can be injected here.pluginTypedStructLens# Let’s say we also want to generate lenses.field:id,integer(),constructor: &is_integer/1,enforce: truefield:role,:user|:admin,constructor: &is_valid_role/1,enforce: truefield:first_name,String.t(),default: "",constructor: &is_string/1field:last_name,String.t(),default: "",constructor: &is_string/1enddefis_valid_role(value)docasevaluedo:admin->{:ok,value}:user->{:ok,value}_->{:error,"invalid role!"}endendend
The text was updated successfully, but these errors were encountered:
Since upstream TypedStruct 0.2.0 now supports plugins, Contructor could be a plugin. This way, it would be composable with other TypedStruct plugins.
The API would look like:
The text was updated successfully, but these errors were encountered: