Longest and Shortest Type Name in .NET 4.0 using LINQ
dotnetcurry.com
Longest and Shortest Type Name in .NET 4.0 using LINQ
1–8 of 8 posts
Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#2Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#3Same code in F# (one line, of course!)
let currentNetTypes = System.AppDomain.CurrentDomain.GetAssemblies() |>
Seq.filter(fun x->x.FullName.Contains("Version=4.0.0.0")) |>
Seq.map(fun x->x.GetExportedTypes()) |> Seq.concat |>
Seq.sortBy(fun x->x.Name.Length);;
To me this reads easier, but I admit to a biased opinion :)Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#4I love F#. Same code in F# (one line, of course!) let currentNetTypes = System.AppDomain.CurrentDomain.GetAssemblies() |> Seq.filter(fun x->x.FullName.Contains("Version=4.0.0.0")) |> Seq.map(fun x->x.GetExportedTypes()) |> Seq.concat |> Seq.sortBy(fun x->x.Name.Length);; To me this reads easier, but I admit to a biased opinion :)
Seq.map ($GetExportedTypes()) |> Seq.sortBy $x.Name.Length
Where $ is some special syntax to indicate "generate a function that uses its parameter as the this parameter for the instance call". I think this has been brought up but perhaps a nice syntax hasn't been found?Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#5I love F#. Same code in F# (one line, of course!) let currentNetTypes = System.AppDomain.CurrentDomain.GetAssemblies() |> Seq.filter(fun x->x.FullName.Contains("Version=4.0.0.0")) |> Seq.map(fun x->x.GetExportedTypes()) |> Seq.concat |> Seq.sortBy(fun x->x.Name.Length);; To me this reads easier, but I admit to a biased opinion :)
The only thing I'm not overly fond of is the repeated "fun x -> x". It'd be nice if there was a way to refer to members without an instance reference. So you could write: Seq.map ($GetExportedTypes()) |> Seq.sortBy $x.Name.Length Where $ is some special syntax to indicate "generate a function that uses its parameter as the this parameter for the instance call". I think this has been brought up but perhaps a nice synt…
def foo(x) { x + 5 }
fun(x) { x + 5}
(x) => x + 5
lambda x -> x + 5
_ + 5
I find I miss the _ syntax more than most syntactical sugar. I don't know how often I have to write things like lambda x: x.foo in Python, where _.foo would serve the same purpose.Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#6I love F#. Same code in F# (one line, of course!) let currentNetTypes = System.AppDomain.CurrentDomain.GetAssemblies() |> Seq.filter(fun x->x.FullName.Contains("Version=4.0.0.0")) |> Seq.map(fun x->x.GetExportedTypes()) |> Seq.concat |> Seq.sortBy(fun x->x.Name.Length);; To me this reads easier, but I admit to a biased opinion :)
currentNetTypes = sorted(
sum(
list(asm.getExportedTypes())
for asm in System.AppDomain.CurrentDomain.GetAssemblies()
if 'Version=4.0.0.0' in asm.FullName),
lambda a, b: cmp(len(a.Name), len(b.Name))
)
Clean, but I love how the |> operator in F# serves to flatten code like this.Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#7It would be pretty cool to try to instantiate each one, and then do a sizeof(instance) on it to see how large the memory footprint is.
Re: Longest and Shortest Type Name in .NET 4.0 using LINQ
#8I love F#. Same code in F# (one line, of course!) let currentNetTypes = System.AppDomain.CurrentDomain.GetAssemblies() |> Seq.filter(fun x->x.FullName.Contains("Version=4.0.0.0")) |> Seq.map(fun x->x.GetExportedTypes()) |> Seq.concat |> Seq.sortBy(fun x->x.Name.Length);; To me this reads easier, but I admit to a biased opinion :)
var currentNetTypes = from a in System.AppDomain.CurrentDomain.GetAssemblies()
from y in a.GetExportedTypes()
where a.FullName.Contains("Version=4.0.0.0")
orderby y.Name.Length
select y;
Or possibly: var currentNetTypes = from a in System.AppDomain.CurrentDomain.GetAssemblies()
.Where(x => x.FullName.Contains("Version=4.0.0.0"))
from y in a.GetExportedTypes()
orderby y.Name.Length
select y;