Adzz / data_schema

Declarative schemas for data transformations.
Apache License 2.0
85 stars 9 forks source link

Allow MFA as casting fns? #18

Closed Adzz closed 2 years ago

Adzz commented 2 years ago

We should be aware that local captures seem to have a performance cost in erlang: https://github.com/beam-telemetry/telemetry/pull/43

We should at the minimum mention that in the docs. We should also see how feasible it is to allow MFA syntax. I guess we would prepend the value onto the argument list which means you could add literals to the fn like so:

field: {:thing, "thing", {MyMod, :my_fun, [1,2]}}

That would get called like this: MyMod.my_fun(input["thing"], 1, 2)

The use case is partially handled by allowing a Module to be provided as a cast fn, but we can't pass in extra arguments that way.

The downside is the potential for the schemas to get quite wide and unreadable. They risk looking a bit scruffy...