Fractran: Difference between revisions

→‎JS Functional: Pruned out a few unused functions
(→‎{{header|JavaScript}}: Added a functionally composed version, attempting primes, but lacking bigInt)
(→‎JS Functional: Pruned out a few unused functions)
Line 2,052:
const bindMay = (mb, mf) =>
mb.Nothing ? mb : mf(mb.Just);
const
 
// chr :: Int -> Char
const chr = String.fromCodePoint;
 
// concatMap :: (a -> [b]) -> [a] -> [b]
const concatMap = (f, xs) =>
Line 2,081 ⟶ 2,078:
return Nothing();
};
 
// findIndices(matching([2, 3]), [1, 2, 3, 1, 2, 3])
//-> {2, 5}
 
// findIndices :: (a -> Bool) -> [a] -> [Int]
Line 2,134 ⟶ 2,128:
}
}
 
// Returns a sequence-matching function for findIndices etc
// findIndices(matching([2, 3]), [1, 2, 3, 1, 2, 3])
// -> [1, 4]
 
// matching :: [a] -> (a -> Int -> [a] -> Bool)
const matching = pat => {
const
lng = pat.length,
bln = 0 < lng,
h = bln ? pat[0] : undefined;
return (x, i, src) =>
bln && h == x &&
eq(pat, src.slice(i, lng + i));
};
 
// ord :: Char -> Int
const ord = c => c.codePointAt(0);
 
// properFracRatio :: Ratio -> (Int, Ratio)
9,659

edits