What is your favorite D feature?
k-five via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 22 02:30:07 PDT 2017
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:
> Hi,
>
> I am currently trying to modernize the D code example roulette
> on the dlang.org front page [1]. Hence, I would love to hear
> about your favorite feature(s) in D.
> Ideas:
> - favorite language construct
> - favorite code sample
> - "only possible in D"
>
> Before you ask, yes - I want to add a couple of cool examples
> to dlang.org (and yep the roulette rotation is currently broken
> [2]).
>
> [1]
> https://github.com/dlang/dlang.org/pulls?q=is%3Apr+is%3Aopen+label%3A%22Frontpage+example%22
> [2] https://github.com/dlang/dlang.org/pull/1757
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote:
Universal Function Call Syntax ( UFCS )
Sample code on my gitgub + screen-shot,
https://github.com/k-five/dren
main code: recursively renaming files based on Regexes
dirEntries( ".", ( args[ 4 ] == "-r" ? SpanMode.depth :
SpanMode.shallow ), false )
.filter!( file => !file.name.matchFirst( regex( args[ 1 ] )
).empty() )
.filter!( file => ( args[ 3 ] == "-f" || args[ 3 ] == "-d" ? (
args[ 3 ] == "-f" ? !file.isDir : !file.isFile ) : (
!file.isSymlink ) ) )
.map!( file => file.name )
.each!( ( string result ) => ( args[ 5 ] == "-y" ?
rename( result, replaceFirst( result, regex( args[ 1 ] ), args[ 2
] ) ) : writeln( "print: ",result, " >> ", replaceFirst( result,
regex( args[ 1 ] ), "\033[1;32m" ~ args[ 2 ] ~ "\033[m" ) ) ) );
More information about the Digitalmars-d
mailing list