Readable v0.1.0 Read View Source

Provides utilities to implement and work with Readable types

Link to this section Summary

Functions

Helper to define readable relation for pair of types. Accepts

Helper to read expression into given type

Link to this section Functions

Link to this macro

defreadable(quoted_to_type, list1, list2) View Source (macro)

Helper to define readable relation for pair of types. Accepts:

  • target type which we want to read
  • source arg expression :: type pair
  • block of code where relation is described

Examples

iex> quote do
...>   import Read
...>   defreadable URI, from: x :: BitString do
...>     URI.parse(x)
...>   end
...> end
...> |> Code.compile_quoted
iex> import Read
iex> read("https://hello.world", URI)
%URI{
  authority: "hello.world",
  fragment: nil,
  host: "hello.world",
  path: nil,
  port: 443,
  query: nil,
  scheme: "https",
  userinfo: nil
}
Link to this function

read(from_expression, to_type) View Source

Helper to read expression into given type

Examples

iex> Read.read("1", Integer)
1