Write a New Function Inside of an Elixir Module

Kyle Gill
InstructorKyle Gill
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Elixir code is organized into groups of functions called modules. You can create your own modules and built on top of predefined modules that are a part of Elixir by default.

Additional resources:

Kyle Gill: [0:00] Almost all Elixir code is organized in modules. Modules is a group of related functions. Elixir has some modules like String and List built in and you can also define your own.

[0:10] Inside a defmodule declaration, you can define functions with the def keyword, using a function name and wrapping the code in the do and end keywords. Because Elixir supports implicit returns, you can write a string as the last line of the function, and it'll be returned when the function is called.

[0:25] To run the project, you can use the interactive Elixir shell and use -S mix as a parameter to compile your project and make your module available in the shell. The full command is iex -S mix. Then you can call a method on your module, HelloWorld.hello, and you can include or leave off parentheses.

egghead
egghead
~ 22 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today