bad unary function

Philippe Sigaud philippe.sigaud at gmail.com
Tue Jul 3 12:14:05 PDT 2012


On Tue, Jul 3, 2012 at 8:58 PM, maarten van damme
<maartenvd1994 at gmail.com> wrote:
> I  have an array of structs and I've written a function that takes as
> argument a struct (and an array but this is besides the point) and
> returns a unique string.

It's not beside the point, I think it's the exact cause of your problem :)


> I wanted to use map to retrieve a string array of all unique strings
> from that array. I've used it this way:
> string [] added=map!("toName(a,parsedschema)")(mod.added);
>
> But I get a compilation error:
>
> bad unary function : toName(a,parsedschema) for type randomStruct.
>
> Is my usage of map wrong?
> what's the compiler trying to explain?

parsedschema is not known in std.functional nor std.algorithm, so the
function template created by std.functional.unaryFun (used by map) is
not recognized by map.

Use a closure to 'transport' parsedschema:

string [] added=map!(a => toName(a,parsedschema))(mod.added);


Philippe


More information about the Digitalmars-d-learn mailing list