This file contains hidden or 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
{ | |
"message": "Hello world!" | |
} |
This file contains hidden or 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
{ | |
"message": "Hello world!" | |
} |
This file contains hidden or 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/dw | |
import mergeWith from dw::core::Objects | |
type Stream<T> = {| | |
data: Array<T>, | |
position: Number | |
|} | |
type Machine = {| |
This file contains hidden or 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 | |
fun while<T>(a, b: (T) -> Boolean) = do { | |
var r = a() | |
fun innerWhile(x) = do { | |
var r = a(x) | |
--- | |
b(r) match { | |
case true -> [r ~ innerWhile(r)] |
This file contains hidden or 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 | |
// See the documentation for this functions | |
import decodeURI, decodeURIComponent, encodeURI, encodeURIComponent from dw::core::URL | |
// Step 1) Enter http://rebrand.ly/dwl-2-playground | |
// Step 2) Copy and paste this code in the transformation editor | |
// You now will see the results in the right pane | |
// Step 3) Implement the parse(str) function | |
// Once you make a test pass, that test will dissapear |
This file contains hidden or 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
fun indexOf<T>(array: Array<T>, elem: T, carry: Number = 0): Number = | |
array match { | |
case [] -> -1 | |
case [head ~ tail] -> | |
if(head == elem) | |
carry | |
else | |
findIndex(tail, elem, carry + 1) | |
} |
This file contains hidden or 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
fun Y(f) = do { | |
var x = | |
((h) -> (arguments) -> using(g = f(h(h))) g(arguments)) | |
(((h) -> (arguments) -> using(g = f(h(h))) g(arguments))) | |
--- | |
f(x) | |
} | |
This file contains hidden or 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 | |
fun sma(list: Array<Number>, window: Number) = | |
0 to (sizeOf(list) - window) map ($ to $ + window - 1) map avg(list[$]) | |
--- | |
sma([90, 40, 45, 100, 101], 2) |
This file contains hidden or 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
fun stdDev(values: Array<Number>): Number = do { | |
var average = avg(values) | |
var squareDiffs = values map do { | |
var diff = $ - average | |
--- | |
diff * diff | |
} | |
--- | |
sqrt(avg(squareDiffs)) | |
} |
This file contains hidden or 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
/** | |
* This function returns a stream. We first populate the stream with a head value, | |
* and a lazy tail. | |
* In this case, we tell the engine the tail is a function call. | |
* That function call will be not be executed UNTIL the value of that call is needed. | |
*/ | |
fun leibnizTerm(n: Number = 0): Array<Number> = | |
[4 / (n + 1) - 4 / (n + 3) ~ leibnizTerm(n + 4)] | |
// ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ | |
// head lazy tail |