# How to normalize function params

**URL:** <https://forum.elixirforum.com/t/how-to-normalize-function-params/44091>\
**Category:** Questions\
**Tags:** elixirconf2021\
**Created:** [November 25, 2021, 12:25pm UTC](https://forum.elixirforum.com/t/how-to-normalize-function-params/44091 "2021-11-25T12:25:47Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sasajuric](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/32/991_2.png) [@sasajuric](https://forum.elixirforum.com/u/sasajuric)\
**Post date:** [November 25, 2021, 7:30pm UTC](https://forum.elixirforum.com/t/how-to-normalize-function-params/44091/5 "2021-11-25T19:30:23Z")

</div>

> [@stefanchrobot](#):
>
> As mentioned in the article, the author is suggesting using [Ecto’ schemaless changesets for this](https://hexdocs.pm/ecto/Ecto.Changeset.html#module-schemaless-changesets). I think the `normalize` function can be written in a pretty generic way.

Yes, on both accounts. I can’t share the code (it’s owned by the clients), but the basic take is something like

```elixir
def normalize(data, types) do
  {%{}, types}
  |> Ecto.Changeset.cast(data, Map.keys(types))
  |> Ecto.Changeset.apply_action(:insert)
end

```

This is probably not enough (e.g. you may want to handle nils and missing keys), but it’s a solid start.

---

_[View the full topic](https://forum.elixirforum.com/t/how-to-normalize-function-params/44091)._
