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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<!-- UPDATE THE INFORMATION HERE --> | |
<groupId></groupId> | |
<artifactId></artifactId> | |
<name></name> |
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
%dw 2.0 | |
output application/json | |
var expandXmlAttrs = (payload) -> | |
payload match { | |
case is Array -> payload map expandXmlAttrs($) | |
case is Object -> payload mapObject { | |
(($$): expandXmlAttrs($)) if ($$.@ == null), | |
(($$): { | |
value: expandXmlAttrs($), |
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
%dw 2.0 | |
input payload csv | |
import * from dw::util::Values | |
import * from dw::Runtime | |
//#region Constants | |
var INF = pow(2, 28) | |
var countryMap = { | |
"USA": "USA", |
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
%dw 2.0 | |
fun splice(arr: Array, index: Number) = | |
if (index == 0) arr[1 to -1] | |
else (arr[0 to index-1] default []) ++ (arr[index+1 to -1] default []) | |
fun shuffle(arr: Array) = | |
(((0 to sizeOf(arr)-1) as Array) reduce (i, s = {res:[], items: arr}) -> do { | |
var ri = floor(random() * sizeOf(s.items)) | |
--- |
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
%dw 2.0 | |
import * from dw::util::Values | |
var INF = pow(2, 28) //infinity constant | |
var ARR = (size, value) -> ((0 to size-1) as Array) map value //make it a bit easier to initialize an array | |
//function for while looping | |
var while = (conditionFn: (s: Any) -> Boolean, whileFn: (s: Any) -> Any, state = {}) -> | |
if (conditionFn(state)) while(conditionFn, whileFn, whileFn(state)) | |
else state |
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
%dw 2.0 | |
fun getEdges(left: Array, right: Array, isEdgeFn: (l: Object, r: Object) -> Boolean) = | |
left reduce ((leftItem, mAccum = { li: 0, edges: [] }) -> | |
(right reduce ((rightItem, iAccum = { li: mAccum.li, ri: 0, edges: mAccum.edges }) -> | |
{ | |
li: iAccum.li, | |
ri: iAccum.ri + 1, | |
edges: iAccum.edges ++ [([iAccum.li, iAccum.ri]) if (isEdgeFn(leftItem, rightItem))] | |
} |
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
%dw 2.0 | |
import * from dw::edi::hlLoop | |
output application/json | |
--- | |
{ | |
"Delimiters": "|>U\n", | |
TransactionSets: { | |
v004010: { |
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
%dw 2.0 | |
fun hlLoop(payload: Object) = | |
((payload.DeliveryItems distinctBy $.PurchaseOrder).PurchaseOrder reduce ((order, accum=hlLoopRoot(payload)) -> | |
payload.DeliveryItems distinctBy $.ProductId reduce ((item, accum=hlLoopPurchaseOrder(order, accum)) -> | |
(payload.DeliveryItems filter ($.ProductId == item.ProductId and $.ProductBatchNumber != null)) reduce ((package, accum=hlLoopItem(item, accum)) -> | |
hlLoopPackage(package, accum) | |
) | |
) | |
)).items |
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
<servers> | |
<server> | |
<id>anypoint-exchange-v2</id> | |
<username>USERNAME</username> | |
<password>PASSWORD</password> | |
</server> | |
<server> | |
<id>MuleRepository</id> | |
<username>USERNAME</username> | |
<password>PASSWORD</password> |
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
%dw 2.0 | |
fun appendNamespace(data, nsSelector: (k: Key) -> Namespace | Null) = | |
data match { | |
case is Array -> data map appendNamespace($, nsSelector) | |
case is Object -> data mapObject do { | |
var ns0 = nsSelector($$) | |
--- | |
if (ns0 != null) ns0#"$($$)": appendNamespace($, nsSelector) | |
else ($$): appendNamespace($, nsSelector) |