-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4475106
commit dc0afae
Showing
14 changed files
with
1,297 additions
and
945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,77 @@ | ||
/**************************************************************************************************************** | ||
* Copyright: © 2017-2024 Ozan Nurettin Süel (aka UIManufaktur) * | ||
* License: Subject to the terms of the Apache 2.0 license, as written in the included LICENSE.txt file. * | ||
* Authors: Ozan Nurettin Süel (aka UIManufaktur) * | ||
*****************************************************************************************************************/ | ||
module uim.collections.classes.iterators.extract;import uim.collections;@safe:/** * Creates an iterator from another iterator that extract the requested column * or property based on a path */class DExtractIterator : D_Collection { this() { super(); } /** * A callable responsible for extracting a single value for each * item in the collection. * / protected callable _extractor; /** * Creates the iterator that will return the requested property for each value * in the collection expressed in somePath * * ### Example: * * Extract the user name for all comments in the array: * * ``` * someItems = [ * ["comment": ["body": 'cool", "user": ["name": 'Mark"]], * ["comment": ["body": 'very cool", "user": ["name": 'Renan"]] * ]; * anExtractor = new DExtractIterator(someItems, "comment.user.name""); * ``` * Params: * Json[string] someItems The list of values to iterate * / this(Json[string] someItems, string aPath) { _extractor = _propertyExtractor(aPath); super(someItems); } // Returns the column value defined in somePath or null if the path could not be followed Json currentValue() { Json[string] myextractor = _extractor; return myextractor(super.currentValue()); } Iterator unwrap() { auto myIterator = innerIterator(); if (cast(I_Collection)myIterator) { myIterator = anIterator.unwrap(); } TODO /* if (myIterator.classname != ArrayIterator.classname) { return this; } * / // ArrayIterator can be traversed strictly. // Let`s do that for performance gains aCallback = _extractor; res = null; myIterator.dup.byKeyValue.each!(kv => res[kv.key] = aCallback(kv.value)); return new DArrayIterator(res); } */} | ||
/**************************************************************************************************************** | ||
* Copyright: © 2017-2024 Ozan Nurettin Süel (aka UIManufaktur) * | ||
* License: Subject to the terms of the Apache 2.0 license, as written in the included LICENSE.txt file. * | ||
* Authors: Ozan Nurettin Süel (aka UIManufaktur) * | ||
*****************************************************************************************************************/ | ||
module uim.collections.classes.iterators.extract; | ||
|
||
import uim.collections; | ||
|
||
@safe: | ||
|
||
/** | ||
* Creates an iterator from another iterator that extract the requested column | ||
* or property based on a path | ||
*/ | ||
class DExtractIterator : D_Collection { | ||
this() { | ||
super(); | ||
} | ||
/** | ||
* A callable responsible for extracting a single value for each | ||
* item in the collection. | ||
* / | ||
protected callable _extractor; | ||
/** | ||
* Creates the iterator that will return the requested property for each value | ||
* in the collection expressed in somePath | ||
* | ||
* ### Example: | ||
* | ||
* Extract the user name for all comments in the array: | ||
* | ||
* ``` | ||
* someItems = [ | ||
* ["comment": ["body": 'cool", "user": ["name": 'Mark"]], | ||
* ["comment": ["body": 'very cool", "user": ["name": 'Renan"]] | ||
* ]; | ||
* anExtractor = new DExtractIterator(someItems, "comment.user.name""); | ||
* ``` | ||
* Params: | ||
* Json[string] someItems The list of values to iterate | ||
* / | ||
this(Json[string] someItems, string aPath) { | ||
_extractor = _propertyExtractor(aPath); | ||
super(someItems); | ||
} | ||
// Returns the column value defined in somePath or null if the path could not be followed | ||
Json currentValue() { | ||
Json[string] myextractor = _extractor; | ||
return myextractor(super.currentValue()); | ||
} | ||
Iterator unwrap() { | ||
auto myIterator = innerIterator(); | ||
if (cast(I_Collection)myIterator) { | ||
myIterator = anIterator.unwrap(); | ||
} | ||
TODO | ||
/* if (myIterator.classname != ArrayIterator.classname) { | ||
return this; | ||
} * / | ||
// ArrayIterator can be traversed strictly. | ||
// Let`s do that for performance gains | ||
aCallback = _extractor; | ||
res = null; | ||
myIterator.dup.byKeyValue.each!(kv => res[kv.key] = aCallback(kv.value)); | ||
return new DArrayIterator(res); | ||
} */ | ||
} |
Oops, something went wrong.