|
IEnumerable in the small in defined as just an interface; for example (.Net sourcecode):
internal interface IEnumerable {
System.Collections.IEnumerator GetEnumerator();
}
Which does nothing but define the need for a method called GetEnumerator that returns a IEnumerator .
If that's what you mean by "My references are to IEnumerable"; then following "your rules"; you should avoid saying:
Count() is not a method of IEnumerable. A state machine can learn; you could probably get a good estimate the 2nd time around; all other things being equal.
If the IEnumerable returns an object, you could even have it return a status report every so often; you're not limited to returning a particular type.
..because "your rules" are stipulating that we ignored all the extension methods that are linked to IEnumerable and by distinction all the sub types of IEnumerable . Meaning you can't imply its a "state machine" because that would require you to first acknowledge the many extension methods for IEnumerable ; because (if you missed it), the extension methods are the bridging code between IEnumerable as an interface to IEnumerable as a state machine i.e. part of what's commonly known as Linq.
What value is there in ignoring reality; Linq (for IEnumerable) exists as a large set of extension methods and sub types, etc.
Whilst its possible to create your own custom interfaces and types to tie in with Linq; that fact alone doesn't discount the large part of extension methods, ... that are considered .Net System.Linq and which is directly typed to the IEnumerable interface.
modified 28-Jan-22 12:49pm.
|
|
|
|
|
You're fixated on one type of implementation; the implementation is up to the author. The author decides how, when, and what to "yield"; which is the whole point.
There are no "rules" .
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Nope... but I'm sure we can agree its become rather pedantic.
An interface on its own is not a state machine; whilst the outcome of this type of implementation:
public class Id : IEnumerable {
private readonly int Value;
public Id(int value) => (Value) = (value);
public IEnumerator GetEnumerator() {
yield return Value;
}
}
..technically yields a state machine; it does not make either IEnumerable or IEnumerator themselves a state machine... they're an implementation requirement.. but then (pedantically) we're getting into the weeds.
Plus this line of discussion has no bearing on the scope of the OP's question wrt to either:
...they've had no problems mastering 'Select and 'Where, 'Aggregate, etc.
What's so useful about deferred evaluation ?
why do I have to trigger iteration with 'Count() to see how many items it has...
In that context IEnumerable should not be considered without Linq; re Select and 'Where, 'Aggregate, etc. are a reference to Linq; and in that context it is the extension methods of Linq that bridge IEnumerable to Linq's implementation of a state machine, and similarly Count() .
I also said...
Whilst its possible to create your own custom interfaces and types to tie in with Linq
It is not a requirement for custom Linq types to implement IEnumerable to use both syntactic styles of Linq. Nor would it be possible for product and sum types to conform to IEnumerable ; because its an implementation that is tied to IEnumerator ; an API designed for iterating over a collection.
|
|
|
|
|
Gerry Schmitz wrote: It's an interface to a forward reading state machine who's final implementation is left up to the author. The whole "internal list" concept is an illusion. I like the analogy of a finite state machine, even if that ... for my students ... is an advanced concept that would probably distract them. i'd rephrase that as: "forward reading finite iteration machine."
"list ... illusion:" trying to prevent the student from assuming there is an internal list is a priority when i teach.
"custom tokenizers:" interesting ... i assume you mean 'Select based IEnumerables.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
@endofunk I am stupefied by the idea anyone guiding a "bright young student" would smother them in such a pile of tangled, redundant, overblown, irrelevant, rhetoric.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Tsk tsk... that type reaction is IMO simply a reflection on an inability to grok the underlying complexity; not on the information and/or its relevance and/or its accuracy. It was after-all intended to provide an indication of the complexity underlying the architecting of Linq.
Ps. Plus my response was to you, not the student -- a good teacher would be able to gauge the level of their audience and adjust the presentation of a complex topic to match that.
|
|
|
|
|
the sweat trying to show off produces often tastes like non-sequiturs
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
An accusation of "showboating"; concludes with an incongruous use of a Latin phrase... Derp
No knowledge is ever to be wasted or ever to be despised
-- Joseph Needham
|
|
|
|
|
endo funk wrote: Tsk tsk... that type reaction is IMO simply a reflection on an inability to grok
Tsk tsk...That reply suggests one or more of the following
1. You did not read the original post
2. You didn't care what the original post asked.
3. You don't understand the context of what student might mean in the original post.
|
|
|
|
|
Nope. I quoted his words (question), and responded to that... a fact you apparently missed.
|
|
|
|
|
endo funk wrote: Nope. I quoted his words (question), and responded to that... a fact you apparently missed.
Your first response in this thread (not sub thread)...
Did not quote anything.
Apparently failed to understand what "bright young student" means.
|
|
|
|
|
Pssst.
...to avoid coming across as either an illiterate or a moron, or a bit of both.
I suggest you compare the Big Bolded Headings before each response paragraph; for example:
Is there any real reason to use an IEnumerable ?
What's so useful about deferred evaluation ?
etc...
...these are in fact direct quotes from the OP's post. Not sure how you missed that..
|
|
|
|
|
I agree. Nothing in that would have been something that one should present in the context of the original question.
|
|
|
|
|
endo funk wrote: Yes; first off IEnumerable was Microsoft implementation of functional programming algebras for a List. It is essentially a monadic data type that encapsulates List; monadic data types are typically designed to conform to a fairly standard set of functional algebras i.e. providing a common API for computations.
Err..no it wasn't.
IEnumerable existed long before linq. It wasn't added to the libraries in any way shape or form to support functional programming.
Now one could make an argument that they should have started from scratch when they did add linq but that is an argument and not a statement of fact.
One could also argue that they should have redid IEnumerable to support linq. However that argument would have been completely wrong since C# was a practical language not a university exercise. Redoing it would have broken the entire existing body of practical work that was using it. And would have been exactly the wrong thing to do for any language when attempting to enhance and not replace that language.
|
|
|
|
|
Extension methods... apparently so obvious that you missed it.
|
|
|
|
|
endo funk wrote: Extension methods... apparently so obvious that you missed it.
Apparently you do not know what you said...
"first off IEnumerable was Microsoft implementation of functional programming algebras for a List. "
And again, no it was not. It existed long before anything associated with functional programming was in the language.
Refutation of that statement has nothing to do with extension methods which were added long after IEnumerable. I can only suppose that you are claiming that they could have used extension methods when implementing linq. Perhaps. But still that has nothing to do with your original incorrect statement.
|
|
|
|
|
Pssst...
Let's review the opening paragraph's of the OP's post.
Quote: Imagine you have bright young student sitting down with you, whom you've introduced to Linq, and generics ... and, they've had no problems mastering 'Select and 'Where, 'Aggregate, etc.
You have introduced them to the use of 'yield return' in a method to return an IEnumerable they can turn into an instance of a collection. They "get that," and get use of yield means they can skip direct assignment to a pre-defined, initialized collection, or, a collection instance reference passed in as an 'out parameter.
And you are trying to explain to them the "deferred iteration/evaluation" aspect of IEnumerable, and the way that enables some advanced practices (function chaining).
To make it a little easier to grasp for those too easily confused by many words, and / or a greater context than just one singled out by one bit of syntax, namely IEnumerable .
The questions were contextual... which apparently you missed completely. Why else would the second question be about deferred evaluation aka lazy evaluation , contextually similar the third question; the fourth question, fifth question, and finally the sixth question.
Contextually it would be rather silly to focus only on the very rudimentary interface definition of IEnumerable when none of the questions related to that... they all were if you missed it related to the behavior of extension methods of IEnumerable .
Ps. if you find the functional programming confusing just say so... as opposed to engaging in an awkward and rather pointless debate; where you clearly had missed the context that was put forward in the OP's post, and similarly the context implied by the questions.
modified 17-Feb-22 20:44pm.
|
|
|
|
|
Hello,
I hope someone can help me on this problem. i have a database (accdb) from access that i want to filter by several comboboxes.
1 st combobox filter row 1 (BaseM)
2nd combobox filters row 2 (Umat) based on the results from the first combobox.
3rd combobox filter row 3 (Gmat) based on combobox 2
etc.
<pre>
private void cmbBaseM_SelectedIndexChanged(object sender, EventArgs e)
{
matTableAdapter.Fill(this.matBaseDataSet.MatBase);
matBaseBindingSource.DataSource = matBaseDataSet.MatBase;
CMBmMat.DataSource = matBaseDataSet.MatBase.Select(US => US.USnumber).Distinct().ToList();
matBaseBindingSource.Filter = "USnumber = " + cmbBaseM.SelectedItem + "";
}
I get an error on the last part
matBaseBindingSource.Filter = "Umat = " + cmbBaseM.SelectedItem + "";
with the message
System.Data.EvaluateException: 'cannot find column [A].'
I have tried so many things that i'm not sure what the way to go is here.
|
|
|
|
|
Try quoting the value, rather than using the value as a pseudo column name e.g.
matBaseBindingSource.Filter = "USnumber = '" + cmbBaseM.SelectedItem + "'";
|
|
|
|
|
Thank you so much that solved the error message, however the method i used does not filter the other combobox. It only fills it with the data from the other row.
Any pointers on how to filter this?
|
|
|
|
|
I think the solution is to use the same method for the SelectedIndex event in all three combo boxes. Then, regardless of which combo box is changed, the same method will fire. Upon firing, the method should construct a Filter string based on all three selections.
Incidentally, you can use interpolated string syntax for easier coding and reading.
matBaseBindingSource.Filter = $"USnumber = '{cmbBaseM.SelectedItem}'";
You can build complex filtering strings when you're using DataSets and DataTables. Check it out.
DataColumn.Expression Property (System.Data) | Microsoft Docs[^]
|
|
|
|
|
It solved the error, but still have troubles with the filtering.
all the examples i find are using SQL i'm using accdb and it seems that this routines don't quite work the same.
|
|
|
|
|
It's true that Access has a limited implementation of SQL, but I don't think you need SQL to do the filtering itself.
If I understand correctly, you have a database with columns BaseM, Umat, and Gmat. You have a DataGridView that displays the rows from this database, and you have combo boxes holding the unique, valid values for each of the mentioned columns. You would like the DataGridView to display only the rows that contain the values selected in the combo boxes.
If that is so, I would load all the rows from the database into the the dataset using SQL (basic select query), and I would then set the binding source's filter to a string that included all three combo box selections. I had mentioned using just one event handler for all three combo boxes. Something like this?
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string[] comboSelections =
{
CmbBaseM.SelectedIndex != -1
? $"BaseM = '{CmbBaseM.GetItemText(CmbBaseM.SelectedItem)}'"
: string.Empty,
CmbUmat.SelectedIndex != -1
? $"Umat = '{CmbUmat.GetItemText(CmbUmat.SelectedItem)}'"
: string.Empty,
CmbGmat.SelectedIndex != -1
? $"Gmat = '{CmbGmat.GetItemText(CmbGmat.SelectedItem)}'"
: string.Empty
};
string filter = string.Join(" AND ", comboSelections.Where(s => !string.IsNullOrEmpty(s)));
MyBindingSource.Filter = filter;
} We first create an array with the selected values, and then we join the non-empty selections with "AND."
modified 24-Jan-22 16:50pm.
|
|
|
|
|
Yes, this actually worked. however it does only filter the fist row BaseM, the next row is not filtered i would expect that the
CmbUmat would be reduced to only the ones that are in the same line as the BaseM.
Got it to work by adding the combobox sources in the start of the form. it works now. Thank you for the help
modified 26-Jan-22 8:09am.
|
|
|
|
|
Oh, I had not thought of the case where the selection in one combo box affected the choices offered in the subsequent combo box! Glad you solved it.
|
|
|
|