[Dlang-internal] [OT] What do you think about declaring functions with lambda syntax?
ddcovery
antoniocabreraperez at gmail.com
Fri Dec 4 11:33:07 UTC 2020
On Friday, 4 December 2020 at 11:12:23 UTC, ddcovery wrote:
> Example:
> ...
This is more functional :-)
import
std.stdio,
std.algorithm,
std.array,
std.conv
;
pure ulong factorial(ulong n) =>
n>1 ? n * factorial(n-1) : 1
;
pure T[] sorted(T)(T[] xs) =>
xs.length == 0 ? [] :
xs[1..$].filter!(x=> x < xs[0]).array.sorted ~
xs[0..1] ~
xs[1..$].filter!(x=> x >= xs[0]).array.sorted
;
void main() =>
[5,6,7,2,3].sorted.map!(i=>i.to!ulong.factorial).writeln
;
More information about the Dlang-internal
mailing list