std.algorithms filter and string[]

Christophe travert at phare.normalesup.org
Thu Apr 19 01:07:11 PDT 2012


Robert Clipsham , dans le message (digitalmars.D:163910), a écrit :
> 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/


I guess you could do something like :

auto files = filter ! (string x => x.isFile) ( (selector==0)? ["."]: sliceOfStrings)

as long as "." passes isFile.

But you may not want immutable for a lazy range.


More information about the Digitalmars-d mailing list