We can refactor our code to eliminate the generic Dict
data structure and represent our articles with specialized Article
composite types.
Let's create a new file in our sixdegrees/
work folder, and name it Articles.jl
. Edit the file by typing in the corresponding module
declaration. Then, add the definition of our type and export
it:
module Articles export Article struct Article content::String links::Vector{String} title::String image::String end end
We could've added the Article
type definition to the Wikipedia.jl
file, but chances are this will grow and it's better to keep them separated instead.
Another thing to note is that both the module
and the type
are Julia entities that are loaded in the same scope. For this reason, we can't use the name Article
for both the module
and the type
—we'd end up with a name clash. However, the pluralized name Articles
is a good name for the module, since it will encapsulate the logic for dealing with articles...