Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 09:00, 8 May 2022
, 2 years ago→{{header|Haskell}}
No edit summary |
|||
Line 1,486:
Or, making alternative choices from the standard libraries:
<lang haskell>import
import Data.Bifunctor (first)
import Data.List (foldl') -- '
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
Line 1,494 ⟶ 1,496:
validISIN :: String -> Bool
validISIN =
((&&) . isinPattern)
<*> (luhn . (show <=<
isinPattern :: String -> Bool
Line 1,501 ⟶ 1,503:
12 == length s
&& all (`elem` capitals) l
&& all (`elem` (capitals
&& head r `elem` digits
where
[l, m, r] = bites s [2, 9, 1]
luhn :: String -> Bool
Line 1,513 ⟶ 1,515:
stream f =
concat $
zipWith ($) (cycle f) (stringInts $ reverse x)
s1 = sum (stream odds)
s2 =
sum $
sum . stringInts . show . (2 *) <$> stream evens
charMap :: M.Map Char Int
Line 1,529 ⟶ 1,527:
stringInts = fromMaybe [] . traverse (`M.lookup` charMap)
bites :: [
bites
(reverse . fst)
(\
([], xs)
capitals, digits :: String
|