digitalmars.D.learn - bad unary function
- maarten van damme (10/10) Jul 03 2012 I have an array of structs and I've written a function that takes as
- bearophile (5/6) Jul 03 2012 Try with a lambda:
- maarten van damme (4/4) Jul 03 2012 Ok, that made sense :)
- bearophile (11/14) Jul 03 2012 Right, sorry. (If I don't run the code I show, then it's usually
- maarten van damme (3/3) Jul 03 2012 Ok, everything works great now.
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. 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?
Jul 03 2012
maarten van damme:string [] added=map!("toName(a,parsedschema)")(mod.added);Try with a lambda: string[] added = mod.added.map!(x => toName(x, parsedschema))(); Bye, bearophile
Jul 03 2012
Ok, that made sense :) Now I get a variable with the Result type and this isn't castable or convertable to an array of strings, how can I extract the actual result now?
Jul 03 2012
maarten van damme:Now I get a variable with the Result type and this isn't castable or convertable to an array of strings,Right, sorry. (If I don't run the code I show, then it's usually broken in some way).how can I extract the actual result now?Often you don't need an array, a lazy range is enough for many purposes. But if you really need an array of strings, then write something like: const added = mod.added.map!(x => x.toName(parsedschema))().array(); array() is inside the module std.array. Bye, bearophile
Jul 03 2012
Ok, everything works great now. thank you maarten
Jul 03 2012