collections with one element only



Date view Thread view Subject view Author view Attachment view

From: SainTiss (saintiss@arklinux.org)
Date: Tue 20 Jan 2004 - 13:56:03 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Is there a way to treat a collection with one element as if it were the 
element itself?

Suppose the collection is a bag, then I guess one could do this:
bag->asSequence->first
But that's not too elegant. Is there a more elegant way?

For example: suppose a certain to-many association should contain exactly one 
element in a certain case, and then there are additional constraints on that 
element. Is the only possible way to specify this something like the 
following?

obj.myToManyAssoc->size = 1 and obj.myToManyAssoc->asSequence->first.name = 
"name"

maybe using "forAll" on the collection is shorter already, but it still 
implies working with a collection...

Thanks in advance,

Hans Schippers

- -- 
Ark Linux - Linux for the Masses (http://arklinux.org)

Capitalism: 
You don't have any cows. The bank will not lend you money to buy cows, 
because you don't have any cows to put up as collateral.

Representative Democracy:
You have two cows. Your neighbors pick someone to tell you who gets the milk. 

In a world without walls and fences, who needs windows and gates?

Hans Schippers
2LIC INF
UA 2003-2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFADTNzXlnUYIbmLOQRAvD5AJ40FwnmyB9Ic3CLkL3WKE3JEMZtnACfd6D/
g7dXXYZCoGQ1WsaQeZqzLdo=
=Qorb
-----END PGP SIGNATURE-----

Date view Thread view Subject view Author view Attachment view