how to remove duplicate code in functional style

berni someone at somemail.de
Fri Nov 23 14:33:40 UTC 2018


I've got the following code, which works, but obviously contains 
duplication. Is there a way to move that 
"dissection_available?...:..." to the place, where it should be?

> return dissection_available
>     ?solution.dup
>              .transposed.map!(a=>a.map!(b=>"?#."[b]).array)
>              
> .zip(dissection.dup.transposed.map!(a=>a.map!(b=>"X#.?"[b]).array))
>              .map!(a=>a[0].to!string~"  "~a[1].to!string)
>              .join("\n")
>              .to!string
>     :solution.dup
>              .transposed.map!(a=>a.map!(b=>"?#."[b]).array)
>              .join("\n")
>              .to!string;

solution and dissection are of type const(int[][]).


More information about the Digitalmars-d-learn mailing list