Skip to content

Instantly share code, notes, and snippets.

@elbow-jason
Last active August 29, 2015 14:25
Show Gist options
  • Save elbow-jason/ee3461d71ef7442d39ff to your computer and use it in GitHub Desktop.
Save elbow-jason/ee3461d71ef7442d39ff to your computer and use it in GitHub Desktop.
import example
defmodule ImportExample do
# on this line Enum is not imported, yet.
import Enum #imports are not Module-wide. they only apply below the import.
def all_funcs do
map([1,2,3], fn n -> n + 1 end) #map is from Enum
end
import Enum, only: [filter: 2]
def only_filter do
[1,2,3]
|> filter(fn n -> rem(n, 2) == 0 end)
#|> map(fn n -> n + 1 end) #uncomment and It wont compile.
end
def import_all_inside do
import Enum # import Enum inside a function
[1,2,3]
|> filter(fn n -> rem(n, 2) == 0 end)
|> map(fn n -> n + 1 end) #but here is works again
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment