Tree datastructures: Difference between revisions
m
→{{header|JavaScript}}
m (→{{header|Haskell}}: Tidied one function.) |
|||
Line 705:
0 < xs.length ? (() => {
const [n, s] = Array.from(xs[0]);
)
);
return [Node(s)(go(firstTreeLines))]▼
▲ .concat(go(rest));
})() : [];
return go(tuples);
Line 770 ⟶ 769:
const compose = (...fs) =>
x => fs.reduceRight((a, f) => f(a), x);
// cons :: a -> [a] -> [a]
const cons = x =>
xs => [x].concat(xs)
// div :: Int -> Int -> Int
Line 825 ⟶ 828:
// lines :: String -> [String]
const lines = s => s.split(/[\r\n]/);
// lt (<) :: Ord a => a -> a -> Bool
const lt = a => b => a < b;
// minimum :: Ord a => [a] -> a
Line 831 ⟶ 837:
foldl1(a => x => x < a ? x : a)(xs)
) : undefined;
// showLog :: a -> IO ()
const showLog = (...args) =>
console.log(
args
.map(JSON.stringify)
.join(' -> ')
);
// span :: (a -> Bool) -> [a] -> ([a], [a])
Line 841 ⟶ 855:
)(xs);
};
// Compose a function (from a tuple to a tuple),
// (with separate transformations for fst and snd)
// splitArrow (***) :: (a -> b) -> (c -> d) -> ((a, c) -> (b, d))
const splitArrow = f => g =>
tpl => Tuple(f(tpl[0]))(
g(tpl[1])
);
// splitAt :: Int -> [a] -> ([a], [a])
Line 853 ⟶ 876:
// uncurry :: (a -> b -> c) -> ((a, b) -> c)
const uncurry = f =>
function(
const
args = Array.from(arguments),
a = 1 < args.length ? (
args
) : args[0];
};
// until :: (a -> Bool) -> (a -> a) -> a -> a
|