I am in the process of tidying up some Elm code and I was wondering how to do the following:
Suppose I have the following File Structure
Project
|
|---Car
|
|--- BMW.elm
|
|--- Mercedes.elm
|...
Suppose that I have divided up the BMW and Mercedes code into different files in order to keep my code small and seperate and so it's much easier for me to just add another file, say Toyota.elm
Now, I would like for any files inside the Project folder to just access all the files in the Car
folder without having to write
import Car.BMW (..)
import Car.Mercedes (..)
...etc...
Ideally, I'd like to just write something like
import Car (..)
and that just gives me access to everything inside each of these files.
Is it possible? If so, what is the best strategy to do so?
Elm doesn't support re-exporting modules so it isn't possible to create a single module which exports a handful of others which you can use to qualify functions. Assuming that you have distinct function names, you could do something like this:
module Utils where
import Foo
import Bar
foo = Foo.foo
bar = Bar.bar
Then you can do
module Other where
import Utils (..)
baz = foo 1 2 3
gak = bar 2 3
But you won't be able to get the fully qualified name to export from the Utils module.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With