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
import scala.util.Random | |
import java.io._ | |
val testdata = "let $values := (" + (Seq.fill(5000)(Random.nextInt(10000))).mkString(",") + ")" | |
val writer = new PrintWriter(new File("c:/tmp/testdata.txt" )) | |
writer.write(testdata) | |
writer.close() |
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
import java.text.Normalizer | |
/** | |
* Problem: Characters with accents or other adornments can be encoded in several different ways in Unicode | |
* However, from a user point of view if they logically mean the same, text search should make no distinction | |
* between the different notations. So it's important to store text in normalized unicode form. Code below shows | |
* how to check if text is normalized and how you can normalize it. | |
**/ | |
object NormalizationTest { |
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
return | |
<groups> | |
{ | |
for $person in $persons/person | |
group by | |
$country := $person/country, | |
$gender := $person/@gender | |
return | |
<group country="{$country}" gender="{$gender}"> | |
<averageAge>{avg($person/age)}</averageAge> |
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
let $persons := | |
<persons> | |
<person gender="male" country="Belgium"> | |
<name>Person A</name> | |
<age>10</age> | |
</person> | |
<person gender="male" country="Netherlands"> | |
<name>Person B</name> | |
<age>20</age> | |
</person> |
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
xquery version "3.0"; | |
declare function local:increase($nums as xs:integer*, $by as xs:integer) as xs:integer* { | |
$nums ! (. + $by) | |
}; | |
let $numbers := (2,3,6,8,12,14) | |
let $increaseByThree := local:increase(?, 3) | |
let $increaseByFour := local:increase(?, 4) | |
return | |
<result> |
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
xquery version "3.0"; | |
let $persons := | |
<persons> | |
<person gender="male"> | |
<country>Belgium</country> | |
<name>Person A</name> | |
<age>10</age> | |
</person> | |
<person gender="male"> |
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
(: | |
Below I show 2 different ways of using the filter function. Both do exactly the same but one uses | |
an inline function expression while the other uses a named function reference | |
:) | |
(: | |
********************************************************************* | |
Example of using filter with inline function expression | |
********************************************************************* |
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
xquery version "3.0"; | |
declare function local:compose($f1 as function(item()) as item(), $f2 as function(item()) as item()) | |
as function(item()) as item() { | |
function($item) as item() { | |
$f2($f1($item)) | |
} | |
}; | |
(: 5 * x - 2 :) |
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
xquery version "3.0"; | |
declare function local:flwor( | |
$ctxt as item(), | |
$find as function(item()) as item()*, | |
$predicate as function(item()) as xs:boolean, | |
$orderBy as function(item()) as item()) as item()* { | |
for $result in $find($ctxt) | |
where $predicate($result) |
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
In Java you often deal with a lot of boilerplate code. A typical example is | |
opening an inputstream, using the inputstream and next closing it. But this | |
simple use case takes writing quite a bit of code.Some of this boilerplate | |
can be factored out by using the loan pattern, where the bank connects a | |
producer and consumer and takes care of the heavy lifting. This code can be | |
further generalized using generics but for illustrating purposes it serves | |
as a nice example. | |
************************************************** | |
Consumer Interface * | |
************************************************** |
OlderNewer