Permalink
Browse files

Merge branch 'master' of github.com:markmandel/Sesame

  • Loading branch information...
markmandel committed May 30, 2012
2 parents 945cb85 + bcf2fd3 commit 671d6d4854bcedcc9e167a0590961b18a827e35b
Showing with 21 additions and 8 deletions.
  1. +4 −4 README.md
  2. +4 −4 sesame/collections.cfm
  3. +13 −0 tests/cases/CollectionsTest.cfc
View
@@ -39,16 +39,16 @@ Functions that allow you manipulate and use structs and arrays much easier
### _collect(any data, function transform) : array ###
-collect data from one array into a whole new array. Transform closure should return the item that i to be added to the new array.
+collect data from a array, structure or query into a whole new array. Transform closure should return the item that i to be added to the new array.
-* data - the array to collect from
+* data - the array / struct / query to collect from
* transform - closure to return the item for the new array
### _collectEntries(any data, function transform) : struct ###
-collect data from an array or a struct into a new struct. The transform function can return either a Map, with a single key to be used as the key, and a 2nd level struct, or an array, where the 1st index in the key, and the 2nd is the value.
+collect data from an array, struct or query into a new struct. The transform function can return either a Map, with a single key to be used as the key, and a 2nd level struct, or an array, where the 1st index in the key, and the 2nd is the value.
-* data - the array / struct to collect from
+* data - the array / struct / query to collect from
* transform - the closure to create the map entry.
### _groupBy(any data, function grouping) : struct ###
View
@@ -19,10 +19,10 @@
--->
<cfscript>
/**
- * collect data from one array into a whole new array. Transform closure should return the item that i
+ * collect data from a array, structure or query into a whole new array. Transform closure should return the item that i
* to be added to the new array.
*
- * @data the array to collect from
+ * @data the array / struct / query to collect from
* @transform closure to return the item for the new array
*/
public array function _collect(required any data, required function transform)
@@ -52,11 +52,11 @@
};
/**
- * collect data from an array or a struct into a new struct.
+ * collect data from an array, struct or query into a new struct.
* The transform function can return either a Map, with a single key to be used as the key, and a 2nd level struct,
* or an array, where the 1st index in the key, and the 2nd is the value.
*
- * @data the array / struct to collect from
+ * @data the array / struct / query to collect from
* @transform the closure to create the map entry.
*/
public struct function _collectEntries(required any data, required function transform)
@@ -16,6 +16,19 @@ component extends="tests.AbstractTestCase"
assertEquals([2, 4, 6, 8], collected);
}
+ /**
+ * test having an child xml structre on collect
+ */
+ public void function testCollectXML()
+ {
+ var xml = "<root><child>1</child><child>2</child><child>3</child></root>";
+ xml = xmlParse(xml);
+
+ var collected = _collect(xml.root.xmlChildren, function(it) { return it.xmlText; });
+
+ assertEquals([1, 2, 3], collected);
+ }
+
/**
* test collecting an query
*/

0 comments on commit 671d6d4

Please sign in to comment.