std.algorithms filter and string[]
Robert Clipsham
robert at octarineparrot.com
Wed Apr 11 07:07:10 PDT 2012
On 11/04/2012 14:55, Russel Winder wrote:
> I am having a dumb n00b moment, but I need to solve this 10 mins ago ;-)
>
> immutable files = ( selector == 0 ) ? [ "." ] : filter ! ( ( string x ) { return x.isFile ; } ) ( sliceOfStrings ) ;
>
> gives me the error:
>
> Error: incompatible types for ((["."]) ? (filter(sliceOfStrings))):
> 'string[]' and 'Result'
>
> which in one universe is fine, but in my universe is a problem as I
> cannot see a way of properly creating a Result instance based on the
> array literal.
>
> (I have a workaround, but I'd prefer to know the proper D idiom for
> this.
>
> Thanks.
>
I don't know that there's an easy way to do array -> arbitrary range as
you ask (or more specifically, Result), however you can use array() from
std.array to go the other way (range -> array).
--
Robert
http://octarineparrot.com/
More information about the Digitalmars-d
mailing list