In this code, I create an array of strings "1" to "10000":
array_of_strings = (1..10000).collect {|i| String(i)}
Does the Ruby Core API provide a way to get an enumerable object that lets me enumerate over the same list, generating the string values on demand, rather than generating an array of the strings?
Here's a further example w...
Basically the same as this question, but in Delphi Prism:
http://stackoverflow.com/questions/29482/cast-int-to-enum-in-c
I manage to do it from a string:
YourEnum := Enum.Parse(TypeOf(YourEnum), "mystr") as YourEnum
But I tried the following, and get a type mismatch error:
YourEnum := 3 as YourNum
Any ideas what the syntax is for...
In .NET, both array and list have Enumerable as ancestor, so a method that accept Enumerable as an argument can receive both array and list as its argument.
I wonder if there is a similar thing in Java?
...
class Foo
{
public static IEnumerable<int> Range(int start, int end)
{
return Enumerable.Range(start, end);
}
public static void PrintRange(IEnumerable<int> r)
{
foreach (var item in r)
{
Console.Write(" {0} ", item);
}
Console.WriteLine();
}
}
class Program
{
...
when trying to use the Enumerable method on a named query, with a Stateless session, as shown in the example at:
http://www.nhforge.org/doc/nh/en/#batch-statelesssession
i am seeing a NotSupportedException. the stack trace is as below:
System.NotSupportedException: Specified method is not supported.
at NHibernate.Impl.StatelessSession...
I want to be able to have an object extend Enumerable in Ruby to be an infinite list of Mondays (for example).
So it would yield: March 29, April 5, April 12...... etc
How can I implement this in Ruby?
...
I know two arrays can be zipped and the result can be iterated with #each. But how do you do it with an unknown number of enumerables?
Let's say
anand = %w(1-0 0.5-0.5 0.5-0.5 1.0)
carlsen = %w(0-1 0.5-0.5 0.5-0.5 1.0)
kramnik = %w(0.5-0.5 0.5-0.5 0.5-0.5 1.0)
players= [anand, carlsen, kramnik]
#something smart
players.each{|round|puts...
I was helping with an answer in this question and it sparked a question of my own.
Pie is an object that has a pieces array made of of PiePiece objects.
Each PiePiece has a flavor attribute
How do I create a hash that looks like this:
# flavor => number of pieces
{
:cherry => 3
:apple => 1
:strawberry => 2
}
This works, but ...
looper = (0..3).cycle
20.times { puts looper.next }
can I somehow find the next of 3? I mean if I can get .next of any particular element at any given time. Not just display loop that starts with the first element.
UPDATE
Of course I went though ruby doc before posting my question. But I did not find answer there ...
UPDATE2
input
...
I have the following method:
public bool IsValid
{
get { return (GetRuleViolations().Count() == 0); }
}
public IEnumerable<RuleViolation> GetRuleViolations(){
//code here
}
Why is it that when I do .Count above it is underlined in red?
I got the following error:
Error 1 'System.Collections.Generic.IEnumerable'
does not c...
If I do
for (int i = 0; i < appSettings.Count; i++)
{
string key = appSettings.Keys[i];
euFileDictionary.Add(key, appSettings[i]);
}
It is working fine.
When I am trying the same thing using
Enumerable.Range(0, appSettings.Count).Select(i =>
{
string Key = appSettings.Keys[i];
string Value = appSettings[i];
euFileDic...
Hello there.
Is there something like C#/.NET's
IEnumerable<int> range = Enumerable.Range(0, 100); //.NET
in Java?
...
k = [1,2,3,4,5]
for n in k
puts n
if n == 2
k.delete(n)
end
end
puts k.join(",")
# Result:
# 1
# 2
# 4
# 5
# [1,3,4,5]
# Desired:
# 1
# 2
# 3
# 4
# 5
# [1,3,4,5]
This same effect happens with the other array iterator, k.each:
k = [1,2,3,4,5]
k.each do |n|
puts n
if n == 2
k.delete(n)
end
end
puts k.join(",")
ha...
Let's say I have a function
def odd_or_even n
if n%2 == 0
return :even
else
return :odd
end
end
And I had a simple enumerable array
simple = [1,2,3,4,5]
And I ran it through map, with my function, using a do-end block:
simple.map do
|n| odd_or_even(n)
end
# => [:odd,:even,:odd,:even,:odd]
How could I do this with...
I can't make any sense of the MSDN documentation for this overload of the Where method that accepts a predicate that has two arguments where the int, supposedly, represents the index of the source element, whatever that means (I thought an enumerable was a sequence and you couldn't see further than the next item, much less do any indexin...
I'm returning a Json'ed annonymous type:
IList<MyClass> listOfStuff = GetListOfStuff();
return Json(
new {
stuff = listOfStuff
}
);
In certain cases, I know that listOfStuff will be empty. So I don't want the overhead of calling GetListOfStuff() (which makes a database call).
So in this case I'm writing:
return Json(
...
I need to parse a URL and be sure there are no duplicate keys in the query string. I've converted the query string to an object using String#toQueryParams()
var queryString = this.parseUri(uri).query.toQueryParams();
On an alert, this comes up as [Object object], but...
queryString.each(function(e) {... });
I get the error that que...
I have a Enumerable object returned from Mongoid (MongoDB object mapper)
using HAML:
= @employees.count
= @employees.class
- @employees.each do |e|
=h e.inspect
the count shows 3
the class shows Enumerable::Enumerator
But only 1 item is printed out
the object is returned in the controller using
@employees = Employee.limit...
There is one method in Lookup<,> that is not in ILookup<,>:
public IEnumerable<TResult> ApplyResultSelector<TResult>(
Func<TKey, IEnumerable<TElement>, TResult> resultSelector);
Why is the return type of Enumerable.ToLookup<>() declared to be ILookup<,> despite the fact that it always seems to return an instance of Lookup<,>? If t...
After this rails app has been running fine for over two years... just started getting this one error on only one page.
ActionView::TemplateError (undefined method `[]' for #<Enumerable::Enumerator:0xb25fbc4>) on line #10 of app/views/notes/_form.rhtml:
7: <%= @n.text_field 'note', :size => 55 %>
8: </label>
9: <%= link_to_function('Cu...