![]() In this article, I presented a number of tips that I think will be very helpful for any Elixir/Phoenix developer and make his/her life somewhat easier. The t/1 command lists all types available in a module as below - iex(4)> t Enum, 3], 3] iex(16)> |> List.flatten() ** (Synta圎rror) iex:16: syntax error before: '|>' (, 3] |> List.flatten(). For example, you can do _info(:md5) to just print md5 key. ![]() Any of those can be passed as arguments, to scope the return value. With no arguments, module_info returns a keyword list, with keys. To list all macros and functions from a module, you can use the below command - iex(3)> exports Minitwitter.Accounts _info, attributes: ], compile:, source: '/Users/meraj/Development/test/elixir/Phoenix_Playground/1.4/minitwitter/lib/minitwitter/accounts/accounts.ex' ], native: false, md5: > ] Tip #11: List All Macros and Functions from a Module This can be easily done with the shortcut :+TAB. Sometimes you may have to print all available modules in a shell in order to diagnose a problem. While in IEx session, you can do the below to compile and load a module from file - iex(1)> c "lib/issues.ex" c "./elixir_book.exs" i Issues i User Term User Data type Atom Raw representation :"Elixir.User" Reference modules Atom Implemented protocols IEx.Info, Inspect, List.Chars, String.Chars Tip #10: Print All Available Modules (17)> #iex:break Relationship iex(3)> User Tip #8: Load a Module or Script in IEx To compile the full project in this case, you can do - iex(4)> recompile Compiling 1 file (.ex) :ok recompile :noop r MinitwitterWeb.PostController r MinitwitterWeb.PostController defmodule Break do. Often time I make changes in source code while in IEx session. In case, it’s the last expression whose value you need to access, a shortcut is just ‘ v’ - iex(8)> new_reversed = v new_reversed iex(10)> Tip #3: Recompile a Project or a Module iex(5)> Enum.reverse() iex(6)> reversed = v(5) reversed iex(8)> ![]() Specially, I often forget to assign value of a long Ecto query or complicated expression and scrolling up and using arrow key to go to the beginning of the expression can be cumbersome. Often time it’s useful to get value of a command executed in the past. Tip #1: Getting Helpįirst thing one should know after ending up in IEx shell is how to get help built into it like below - Erlang/OTP 22 Interactive Elixir (1.10.2) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> h h(Enum) h(Enum.reverse/1) Enum.reverse() Tip #2: Get Value of Past Expression(s) Throughout the article, I will show output from real iex session but in most cases output will be truncated and annotated to suit this article. You can launch IEx shell from the command line simply typing iex or if you want to launch a phoenix project by typing iex -S mix phx.server or typing iex -S mix while in a mix based Elixir project. Some of the things may be different or may not even work if you are using a different version of IEx.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |