The ‘use’ Macro in Elixir.

Information on ‘use’ is Hard to Find.

  • ‘use’ is not searchable: Google searching “how to use ‘use’ in elixir” doesn’t return much information.
  • ‘use’ is hidden in the elixir documentation: It’s in the Elixir documentation for alias, require, and import.
  • There is no example for __using__ in a module: The elixir documentation states that ‘use’ calls the __using__ callback, but there’s no example implementation of this callback.

So What Is ‘use’?

  • Use is a tool to reuse code just like require, import, and alias.
  • Use simply calls the __using__ macro defined in another module.
  • The __using__ macro allows you to inject code into another module.

Why ‘use’ Instead of Import?

Use Allows You to Create Templates.

How Phoenix Leverages ‘use’.

Summary

--

--

--

Software Engineer. I create educational content focused on technology for mobile and web applications.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automating with Powershell

How Flutter changed Development for the Better

Valgrind in macOS with Docker

Result of the above command

I cut my team in half and doubled their output in 30 days.

‘Tu Sirf Diagram Dikha, Baaki Main Likhta Hu’ — Happy Engineers Day!

How to Build and Deploy Web Service and Client in Java

My First Blender Experience Broke me

Scala: map vs flatMap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Brooklin Myers

Brooklin Myers

Software Engineer. I create educational content focused on technology for mobile and web applications.

More from Medium

An opinionated Elixir Style Guide

Elixir tap and then macros — life-saving helpers

Listing Modules under a Namespace in Elixir

Beam me up!