module Advent.OCR (
parseLetters
, parseLettersWith
, parseLettersEither
, unsafeParseLetters
, parseAsciiMap
, asciiMapToLetters
, LetterMap
, defaultLetterMap
, parseLetters'
, parseLettersWith'
, parseLettersEither'
, unsafeParseLetters'
, asciiMapToLetters'
) where
import Advent.OCR.Internal
import Data.Bifunctor
import Data.Maybe
import Data.Set (Set)
import qualified Data.Set as S
parseLettersWith'
:: LetterMap
-> (a -> Int)
-> (a -> Int)
-> Set a
-> Maybe String
parseLettersWith' :: forall a.
LetterMap -> (a -> Int) -> (a -> Int) -> Set a -> Maybe String
parseLettersWith' LetterMap
lm a -> Int
f a -> Int
g = LetterMap -> Set Point -> Maybe String
parseLettersV2 LetterMap
lm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b a. Ord b => (a -> b) -> Set a -> Set b
S.map (\a
x -> forall a. a -> a -> V2 a
V2 (a -> Int
f a
x) (a -> Int
g a
x))
parseLettersWith
:: (a -> Int)
-> (a -> Int)
-> Set a
-> Maybe String
parseLettersWith :: forall a. (a -> Int) -> (a -> Int) -> Set a -> Maybe String
parseLettersWith = forall a.
LetterMap -> (a -> Int) -> (a -> Int) -> Set a -> Maybe String
parseLettersWith' LetterMap
defaultLetterMap
parseLetters'
:: LetterMap
-> Set (Int, Int)
-> Maybe String
parseLetters' :: LetterMap -> Set (Int, Int) -> Maybe String
parseLetters' LetterMap
lm = LetterMap -> Set Point -> Maybe String
parseLettersV2 LetterMap
lm forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> Set a -> Set b
S.mapMonotonic (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. a -> a -> V2 a
V2)
parseLetters
:: Set (Int, Int)
-> Maybe String
parseLetters :: Set (Int, Int) -> Maybe String
parseLetters = LetterMap -> Set (Int, Int) -> Maybe String
parseLetters' LetterMap
defaultLetterMap
parseLettersEither'
:: LetterMap
-> Set (Int, Int)
-> Maybe [Either (Set (Int, Int)) Char]
parseLettersEither' :: LetterMap -> Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char]
parseLettersEither' LetterMap
lm = (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> Set a -> Set b
S.mapMonotonic) (\(V2 Int
x Int
y) -> (Int
x, Int
y))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LetterMap -> Set Point -> Maybe [Either (Set Point) Char]
parseLettersEitherV2 LetterMap
lm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> Set a -> Set b
S.mapMonotonic (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a. a -> a -> V2 a
V2)
parseLettersEither
:: Set (Int, Int)
-> Maybe [Either (Set (Int, Int)) Char]
parseLettersEither :: Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char]
parseLettersEither = LetterMap -> Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char]
parseLettersEither' LetterMap
defaultLetterMap
unsafeParseLetters'
:: LetterMap
-> Set (Int, Int)
-> String
unsafeParseLetters' :: LetterMap -> Set (Int, Int) -> String
unsafeParseLetters' LetterMap
lm =
forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"Advent.OCR.unsafeParseLetters': Unable to parse letters")
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LetterMap -> Set (Int, Int) -> Maybe String
parseLetters' LetterMap
lm
unsafeParseLetters
:: Set (Int, Int)
-> String
unsafeParseLetters :: Set (Int, Int) -> String
unsafeParseLetters =
forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"Advent.OCR.unsafeParseLetters: Unable to parse letters")
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set (Int, Int) -> Maybe String
parseLetters
parseAsciiMap
:: Set Char
-> String
-> Set (Int, Int)
parseAsciiMap :: Set Char -> String -> Set (Int, Int)
parseAsciiMap Set Char
c = forall a b. (a -> b) -> Set a -> Set b
S.mapMonotonic (\(V2 Int
x Int
y) -> (Int
x, Int
y)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Char -> String -> Set Point
parseAsciiMapV2 Set Char
c
asciiMapToLetters'
:: Set Char
-> LetterMap
-> String
-> Maybe String
asciiMapToLetters' :: Set Char -> LetterMap -> String -> Maybe String
asciiMapToLetters' Set Char
c LetterMap
lm = LetterMap -> Set Point -> Maybe String
parseLettersV2 LetterMap
lm forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set Char -> String -> Set Point
parseAsciiMapV2 Set Char
c
asciiMapToLetters
:: Set Char
-> String
-> Maybe String
asciiMapToLetters :: Set Char -> String -> Maybe String
asciiMapToLetters Set Char
c = Set Char -> LetterMap -> String -> Maybe String
asciiMapToLetters' Set Char
c LetterMap
defaultLetterMap