digitalmars.D - std.algorithms filter and string[]
- Russel Winder (22/22) Apr 11 2012 I am having a dumb n00b moment, but I need to solve this 10 mins ago ;-)
- Matt Peterson (3/20) Apr 11 2012 Use the array(...) function from std.array to convert "Result" to
- David Nadlinger (3/9) Apr 11 2012 filter() is lazy – just use array() for eager evaluation?
- Robert Clipsham (7/18) Apr 11 2012 I don't know that there's an easy way to do array -> arbitrary range as
- travert phare.normalesup.org (Christophe) (5/32) Apr 19 2012 I guess you could do something like :
I am having a dumb n00b moment, but I need to solve this 10 mins ago ;-) immutable files =3D ( selector =3D=3D 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. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Apr 11 2012
On Wednesday, 11 April 2012 at 13:55:45 UTC, 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.Use the array(...) function from std.array to convert "Result" to the string[].
Apr 11 2012
On Wednesday, 11 April 2012 at 13:55:45 UTC, 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: […]filter() is lazy – just use array() for eager evaluation? David
Apr 11 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/
Apr 11 2012
Robert Clipsham , dans le message (digitalmars.D:163910), a écrit :On 11/04/2012 14:55, Russel Winder wrote: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.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/
Apr 19 2012