September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,20 +1,55 @@
(lstRanges => {
// charRange :: Char -> Char -> [Char]
function charRange(cFrom, cTo) {
let [m, n] = [cFrom, cTo]
.map(s => s.codePointAt(0));
(() => {
// enumFromTo :: Enum a => a -> a -> [a]
const enumFromTo = (m, n) => {
const [intM, intN] = [m, n].map(fromEnum),
f = typeof m === 'string' ? (
(_, i) => chr(intM + i)
) : (_, i) => intM + i;
return Array.from({
length: (n - m) + 1
}, (_, i) => String.fromCodePoint(m + i));
}
length: Math.floor(intN - intM) + 1
}, f);
};
// GENERIC FUNCTIONS ------------------------------------------------------
// TEST
return lstRanges
.map(([from, to]) => charRange(from, to).join(' '))
.join('\n')
// compose :: (b -> c) -> (a -> b) -> (a -> c)
const compose = (f, g) => x => f(g(x));
})([['a', 'z'], ['א','ת'],['α', 'ω'],['🐐', '🐟']]);
// chr :: Int -> Char
const chr = x => String.fromCodePoint(x);
// ord :: Char -> Int
const ord = c => c.codePointAt(0);
// fromEnum :: Enum a => a -> Int
const fromEnum = x => {
const type = typeof x;
return type === 'boolean' ? (
x ? 1 : 0
) : type === 'string' ? ord(x) : x;
};
// map :: (a -> b) -> [a] -> [b]
const map = (f, xs) => xs.map(f);
// show :: a -> String
const show = x => JSON.stringify(x);
// uncurry :: Function -> Function
const uncurry = f => args => f.apply(null, args);
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
// unwords :: [String] -> String
const unwords = xs => xs.join(' ');
// TEST -------------------------------------------------------------------
return unlines(map(compose(unwords, uncurry(enumFromTo)), [
['a', 'z'],
['α', 'ω'],
['א', 'ת'],
['🐐', '🐟']
]));
})();