Changeset 1780

Show
Ignore:
Timestamp:
11/25/08 06:08:11 (22 months ago)
Author:
Chuck.Esterbrook
Message:

Fixed: Cannot use for expressions on non-generic enumerables.
ticket:85

Location:
cobra/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r1769 r1780  
    226226 
    227227* Fixed: Cannot properly invoke delegates whose delegate types come from binary libraries. 
     228 
     229* Fixed: Cannot use `for` expressions on non-generic enumerables. ticket:85 
  • cobra/trunk/Source/Cobra.Lang/Native.cs

    r1778 r1780  
    758758        } 
    759759 
     760        static public List<TOut> For<TIn, TOut>(IEnumerable list, ForGet<TIn, TOut> forGet) { 
     761                List<TOut> results = new List<TOut>(); 
     762                foreach (TIn item in list) 
     763                        results.Add(forGet(item)); 
     764                return results; 
     765        } 
     766 
     767        static public List<TOut> For<TIn, TOut>(IEnumerable list, ForWhereGet<TIn, TOut> forWhereGet) { 
     768                List<TOut> results = new List<TOut>(); 
     769                foreach (TIn item in list) { 
     770                        TOut value; 
     771                        if (forWhereGet(item, out value)) 
     772                                results.Add(value); 
     773                } 
     774                return results; 
     775        } 
     776 
    760777        static private void ProcessGetSliceArgs(int count, ref int? start, ref int? stop, ref int? step) { 
    761778                if (start==null) 
  • cobra/trunk/Tests/240-generics/100-use-generics-collections/610-for-expr-generic-list.cobra

    r1264 r1780  
    4747                words = for word in words where word <> 'asdf'   # assign for expr back to source variable 
    4848                assert words == ['aoeu'] 
     49 
     50                # okay sneak in a non-generic for expr 
     51                ie as System.Collections.IEnumerable = [1, 2, 3] 
     52                assert [2, 4, 6] == for i in ie get 2*(i to int) 
     53                assert [4, 6] == for i in ie where (i to int) > 1 get 2*(i to int)