Last active
August 29, 2015 14:25
-
-
Save elbow-jason/ee3461d71ef7442d39ff to your computer and use it in GitHub Desktop.
import example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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