Extra v0.2.0 Struct.Extra

Extensions to the built-in Struct module.

Link to this section Summary

Functions

Drops the given keys from the struct while honoring the struct’s original fields

Convenience function for extracting the top-level keys within a struct

Merges two of the same structs together

Link to this section Functions

Link to this function drop(record, fields)
drop(struct, Enum.t) :: struct

Drops the given keys from the struct while honoring the struct’s original fields.

Link to this function keys(x)
keys(struct) :: [key :: any]

Convenience function for extracting the top-level keys within a struct.

This excludes the __struct__ key.

Link to this function merge(a, b)
merge(struct, struct) :: struct

Merges two of the same structs together.

Using Map.merge/2 is not feasible because structs typically have default values of nil. This function will not allow values of nil to overwrite non-nil values on merge.