program Project1;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Spring,
Spring.Collections;
type
TProduct = class
public
Name: string;
Category: string;
Price: Double;
InStock: Integer;
constructor Create(const AName, ACategory: string; APrice: Double; AInStock: Integer);
end;
constructor TProduct.Create(const AName, ACategory: string; APrice: Double; AInStock: Integer);
begin
Name := AName;
Category := ACategory;
Price := APrice;
InStock := AInStock;
end;
var
Products: IList;
Nombres: IEnumerable<string>;
begin
try
Products := TCollections.CreateObjectList(True);
Products.AddRange([
TProduct.Create('artilugio', 'cacharro', 192.43, 3),
TProduct.Create('cacharro', 'electrónica', 13.65, 10),
TProduct.Create('pongo', 'cacharro', 52.22, 0),
TProduct.Create('cosa', 'electrónica', 11.33, 5),
TProduct.Create('trasto', 'cacharro', 43.44, 1)
]);
Writeln('Buscando nombres de electronica...');
Nombres := Products
.Where(function(const p: TProduct): Boolean
begin
Result := p.Category = 'electrónica';
end)
.Map<string>(function(const p: TProduct): string
begin
Result := p.Name;
end);
for var s in Nombres do
Writeln('Producto: ' + s);
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.