Dragon curve: Difference between revisions
Content added Content deleted
(adding lambdatalk) |
m (→JS ES6: Minor tidying) |
||
Line 2,439: | Line 2,439: | ||
<lang javascript>(() => { |
<lang javascript>(() => { |
||
'use strict'; |
'use strict'; |
||
// ------------------ DRAGON CURVE ------------------- |
|||
// dragonCurve :: [[Int]] -> [[Int]] |
// dragonCurve :: [[Int]] -> [[Int]] |
||
Line 2,461: | Line 2,463: | ||
// ---------------------- |
// ---------------------- TEST ----------------------- |
||
// main :: IO () |
// main :: IO () |
||
const main = () => |
const main = () => |
||
Line 2,475: | Line 2,477: | ||
// ----------------------- |
// ----------------------- SVG ----------------------- |
||
// svgFromPointLists :: Int -> Int -> |
// svgFromPointLists :: Int -> Int -> |
||
Line 2,484: | Line 2,486: | ||
polyline = xs => |
polyline = xs => |
||
`<polyline points="${unwords(concat(xs).map(showJSON))}"/>`, |
`<polyline points="${unwords(concat(xs).map(showJSON))}"/>`, |
||
[x, y, mx, my] = |
[x, y, mx, my] = ap([minimum, maximum])( |
||
Array.from(unzip(concat(xyss))) |
Array.from(unzip(concat(xyss))) |
||
), |
), |
||
Line 2,506: | Line 2,508: | ||
// ---------------- |
// ---------------- GENERIC FUNCTIONS ---------------- |
||
// Just :: a -> Maybe a |
// Just :: a -> Maybe a |
||
Line 2,539: | Line 2,541: | ||
// |
// ap (<*>) :: [(a -> b)] -> [a] -> [b] |
||
const |
const ap = fs => |
||
// The sequential application of each of a list |
// The sequential application of each of a list |
||
// of functions to each of a list of values. |
// of functions to each of a list of values. |
||
Line 2,613: | Line 2,615: | ||
// iterate :: (a -> a) -> a -> Gen [a] |
// iterate :: (a -> a) -> a -> Gen [a] |
||
const iterate = f => |
const iterate = f => |
||
function*(x) { |
function* (x) { |
||
let v = x; |
let v = x; |
||
while (true) { |
while (true) { |