{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TupleSections #-}
module Examples.Layers where

import Proton
import Data.Profunctor
import Data.Profunctor.Rep
import Data.Profunctor.MStrong
import Proton.Algebraic
import qualified Data.Map as M
import Data.Foldable
import Data.Maybe

imgLayers :: [[Int]]
imgLayers :: [[Int]]
imgLayers = [ [0, 1, 0, 1]
            , [2, 3, 3, 2]
            ]

-- done :: [Int]
-- done = imgLayers & pointWise *% head . dropWhile (== 0)

-- selector :: (Ord k, Corep p ~ M.Map k, Corepresentable p) => Optic p s [Maybe s] s [k]
-- selector = listLens id (\(m, k) -> flip M.lookup m <$> k)

-- done' = M.fromList [(1 :: Int, [1, 10]), (2, [2, 20]), (3, [3, 30])]  & selector . convolving *% M.findWithDefault 99 1

forward :: Profunctor p => (s -> a) -> Optic p s t a t
forward :: (s -> a) -> Optic p s t a t
forward f :: s -> a
f = (s -> a) -> Optic p s t a t
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap s -> a
f

back :: Profunctor p => (x -> t) -> Optic p s t s x
back :: (x -> t) -> Optic p s t s x
back f :: x -> t
f = (x -> t) -> Optic p s t s x
forall (p :: * -> * -> *) b c a.
Profunctor p =>
(b -> c) -> p a b -> p a c
rmap x -> t
f

lookup'er :: Eq a => AlgebraicLens (a, b) (a, Maybe b) a a
lookup'er :: AlgebraicLens (a, b) (a, Maybe b) a a
lookup'er = ((a, b) -> a)
-> ([(a, b)] -> a -> (a, Maybe b))
-> Optic p (a, b) (a, Maybe b) a a
forall (p :: * -> * -> *) s a b t.
MStrong p =>
(s -> a) -> ([s] -> b -> t) -> Optic p s t a b
listLens (a, b) -> a
forall a b. (a, b) -> a
fst (\xs :: [(a, b)]
xs i :: a
i -> (a
i, a -> [(a, b)] -> Maybe b
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup a
i [(a, b)]
xs))

-- test :: IO ()
-- test = do
--     print $ [([1, 2] , "one" :: String), ([10, 0], "two")] & lookup'er . pointWise *% maximum