Attention: Looking forward to your feedback about the new refactoring branch

88 views
Skip to first unread message

Baoquan Zuo

unread,
Apr 19, 2013, 12:25:58 AM4/19/13
to spri...@googlegroups.com
Hi all,

Stefan has working for a while on the refactoring of the Collections framework. Here it is a short description on what happened:

Background:
The original IEnumerable<T> interface is very easy to use but it contains many "extension methods" which cause HUGE and exploding binary size compared to the RTL version. 

Restrictions:
1) Delphi does NOT support interface helper
2) Delphi does NOT support generics methods for interfaces
3) smart linker won't work for interface


What's New

At present, we moved MOST extension methods (e.g. Where, Take, TakeWhile, First, FirstOrDefault, Single, SingleOrDefault, etc.) from Spring.Collections.IEnumerable<T> interface to Enumerable<T> record which can be accessed by IEnumerable<T>.AsEnumeable method.

The most benefit of introducing Enumerable<T> record is obviously reducing the binary size (Need prove) and make generic methods (like Select<T>) possible.

Introduced these NEW extension methods:
  • Select, SelectMany
  • Aggregate, GroupBy, ToLookup
  • GroupJoin, Join, OrderBy, ThenBy
  • ExceptWith, IntersectWith and UnionWith
NOTE: These changes are still not final decision so your feedback are very important.

Baoquan Zuo

unread,
Apr 19, 2013, 12:28:41 AM4/19/13
to spri...@googlegroups.com

Paul

Nick Hodges

unread,
Apr 19, 2013, 1:51:56 PM4/19/13
to spri...@googlegroups.com
Could we get Head and Tail, where head is the first item, and Tail is everything but the first item?


--
You received this message because you are subscribed to the Google Groups "Spring Framework for Delphi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring4d+u...@googlegroups.com.
To post to this group, send email to spri...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nick Hodges

unread,
Apr 19, 2013, 1:55:14 PM4/19/13
to spri...@googlegroups.com
This is going to make my book a lot harder.  ;-)

Glienke, Stefan

unread,
Apr 22, 2013, 2:14:33 AM4/22/13
to spri...@googlegroups.com

We are not talking about a linked list here, aren’t we?

Nick Hodges

unread,
Apr 22, 2013, 3:40:37 PM4/22/13
to spri...@googlegroups.com

No, it would be like something from Haskell -- like

Procedure TotalList(aList: IList);
begin
  while aList.First <> nil then
    Result := aList.First + TotalList(aList.Rest);
end;

Crudely put -- explained 100 times better here:


Nick

Baoquan Zuo

unread,
Apr 22, 2013, 7:34:58 PM4/22/13
to spri...@googlegroups.com
It is always interesting to use the collections framework in such cases. Actually Skip(1) is an option :-) Maybe next time you may use Skip(2) to get another rest. (Putting the Rest / Tail in the interface doesn't also make consumers know how it exactly behaviors when there is no elements or just one element)

P.S. 
1) Invoking the First method when the collections is empty will raise an exception. Use FirstOrDefault instead. (Or not IsEmpty)
2) We need to create a snapshot by using ToList/ToArray, etc. whenever the enumerable collection maybe changed. Otherwise the behavior is unexpected. Exception will be raised in future by applying version to collections.
e.g. 
list.AddRange(list.Skip(1).ToArray);

Baoquan Zuo

unread,
Apr 22, 2013, 7:39:47 PM4/22/13
to spri...@googlegroups.com
P.S. 
1) Invoking the First method when the collections is empty will raise an exception. Use FirstOrDefault instead. (Or not IsEmpty)
2) We need to create a snapshot by using ToList/ToArray, etc. whenever the enumerable collection maybe changed. Otherwise the behavior is unexpected. Exception will be raised in future by applying version to collections.
e.g. 
list.AddRange(list.Skip(1).ToArray);

Paul

Glienke, Stefan

unread,
Apr 23, 2013, 2:10:57 AM4/23/13
to spri...@googlegroups.com

Because in Haskell lists are implemented as singly linked lists.

Reply all
Reply to author
Forward
0 new messages