Named multi-imports
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 17 14:49:38 PDT 2017
On 17.08.2017 23:03, aberba wrote:
> On Wednesday, 16 August 2017 at 13:57:17 UTC, jmh530 wrote:
>> On Wednesday, 16 August 2017 at 09:54:41 UTC, aberba wrote:
>>>
>>> This looks really clean for code modularity.
>>>
>>> import io = std.stdio : {writeln, write}, ...
>>
>> What does this add? A line like below would be confusing.
>> import io = std.stdio : {writeln, write}, writefln;
>>
>> The following code compiles and the imports are less confusing.
>>
>> import io = std.stdio : writeln, write;
>> import std.stdio : writefln;
>>
>> void main()
>> {
>> io.write("foo");
>> io.writeln("bar");
>> writefln("My items are %(%s %).", [1,2,3]);
>> }
>
> Its more like this:
>
> import oo = {std.stdio : {writeln, write}, std.algorithm: {filter, map},
> …};
>
> oo.writeln();
> oo.write();
> oo.filter(...);
> oo.map(...);
>
private struct oo{
import std.stdio: writeln, write;
import std.algorithm: filter, map;
// …
}
void main(){
oo.write("result: ");
oo.writeln(oo.map!(x=>x/2)(oo.filter!(x=>x%2==0)([1,2,3,4,5,6,10])));
}
More information about the Digitalmars-d
mailing list