Created
June 18, 2019 00:59
-
-
Save tonymorris/ea6705967a798d8e14caae63e3e3fb35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Functor.Identity | |
data A = A | |
deriving (Eq, Show) | |
data B = B | |
deriving (Eq, Show) | |
data C = C | |
deriving (Eq, Show) | |
data D = D | |
deriving (Eq, Show) | |
-- solved by: classy lens | |
getC_ABC :: (A, B, C) -> C | |
getC_ABC (_, _, c) = c | |
getC_ABCD :: (A, B, C, D) -> C | |
getC_ABCD (_, _, c, _) = c | |
insertRecord_ABC' :: f (A, B, C) -> [f (A, B, C)] -> [f (A, B, C)] | |
insertRecord_ABC' = (:) | |
insertRecord_ABC :: (A, B, C) -> [(A, B, C)] -> [(A, B, C)] | |
insertRecord_ABC r rs = runIdentity <$> (insertRecord_ABC' (Identity r) (Identity <$> rs)) | |
insertRecord_ABCD :: (A, B, C, D) -> [(A, B, C, D)] -> [(A, B, C, D)] | |
insertRecord_ABCD r rs = let liftRec (a, b, c, d) = (d, (a, b, c)) | |
unliftRec (d, (a, b, c)) = (a, b, c, d) | |
in unliftRec <$> (insertRecord_ABC' (liftRec r) (liftRec <$> rs)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment