Permutations on Generic Objects #977
-
Hi! I was trying to loop over the permutations of a list of objects. The objects are of a custom type, not builtin. It does work but only generates a single permutation and therefore iterates once and then stops. Do they need to implement some function for it to work? I couldn't find anything in the documentation. The same code works when using ints |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Would you please share an example that demonstrates the problem? I attempted to replicate with custom objects and behavior matched for both |
Beta Was this translation helpful? Give feedback.
-
Works fine with objects of custom types, even anonymous types as shown below: using MoreLinq;
var objs = new[]
{
new { Foo = 1 },
new { Foo = 2 },
new { Foo = 3 },
};
Console.WriteLine(objs.Permutations()
.Select(e => e.ToDelimitedString(", "))
.ToDelimitedString(Environment.NewLine));
No. |
Beta Was this translation helpful? Give feedback.
-
So looks like you indeed spotted a bug. It should be breaking/overflowing instead of returning the wrong result of a single permutation when the source sequence is over some length. In fact, I noticed that for sequences of length 13 and above, it returns the wrong number of permutations! I have filed this as bug #978. |
Beta Was this translation helpful? Give feedback.
So looks like you indeed spotted a bug. It should be breaking/overflowing instead of returning the wrong result of a single permutation when the source sequence is over some length. In fact, I noticed that for sequences of length 13 and above, it returns the wrong number of permutations!
I have filed this as bug #978.