suggestions icon indicating copy to clipboard operation
suggestions copied to clipboard

Import all public functions/types from a module

Open CrowdHailer opened this issue 5 years ago • 4 comments

Instead of explicitly having to import everything you want unqualified it would be useful to be able to import all at once https://gleam.run/tour/modules.html

import web/helpers.*
import web/helpers.{*types, *functions}

For something like a web controller there is a clear context and so not as much worry about tracing the origin of functions like set_header get_header etc. You could even limit files to a single wildcard import to make it easier to find the definition of functions

CrowdHailer avatar Apr 28 '20 06:04 CrowdHailer

I'm not a fan of the unqualified style and would not like to encourage its use. In the example you've given it does not seem like it would be unergonomic to either import the functions used or to write midas.set_header, perhaps you have other examples which might persuade me otherwise?

lpil avatar Apr 28 '20 08:04 lpil

import http/methods.*

case route {
   tuple(GET, []) ->
}

CrowdHailer avatar Apr 30 '20 08:04 CrowdHailer

In my code I've been importing the ones I use and that's been fine, there's only really 4 in a REST app.

lpil avatar Apr 30 '20 08:04 lpil

Ok, you might convince me on this. I've slimmed down the Midas API to only the functionality I actually used in my last two projects. There wasn't that much.

I'm ruminating on how valuable I think this would be

CrowdHailer avatar May 01 '20 08:05 CrowdHailer