vonH
Is there an elixir function that prints out the type of a value and display its fields?
Is there an elixir function to tells the type of a value and display its fields(if it has any)?
For instance I am leaning Plug and want to know what type conn is and display its fields.
One more thing does Elixir have structs or objects as they are understood in languages like C or Pascal?
Most Liked
chrismccord
See the the i/1 helper docs in IEx:
Prints information about the data type of any given term.
## Examples
iex> i(1..5)
Will print:
Term
1..5
Data type
Range
Description
This is a struct. Structs are maps with a __struct__ key.
Reference modules
Range, Map
Example:
iex(19)> i File.stat!("README.md")
Term
%File.Stat{access: :read_write, atime: {{2017, 3, 31}, {21, 24, 2}}, ctime: {{2017, 3, 31}, {18, 56, 52}}, gid: 20, inode: 10353339, links: 1, major_device: 16777220, minor_device: 0, mode: 33188, mtime: {{2017, 3, 31}, {18, 56, 52}}, size: 2879, type: :regular, uid: 501}
Data type
File.Stat
Description
This is a struct. Structs are maps with a __struct__ key.
Reference modules
File.Stat, Map
Implemented protocols
IEx.Info, Inspect
OvermindDL1
inspect(blahSomething) returns a string representation of whatever blahSomething is.
IO.inspect(blahSomething) prints the string representation of whatever blahSomething is to the standard output.
All of this is documented in the manual too. ![]()
Elixir’s structs are like structs in pascal or c yes, underneath they are just statically keyed maps, they are not packed in memory as in pascal or c though, especially since memory is not really a concept on the EVM, it manages it for you.
There is no static typing, however the dialyzer tool (also detailed in the manual) is an awesome tool that runs over your code and checks the success typing of your program, Dialyxer is a dead-simple Elixir interface for using it and I highly recommend it. ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









