Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add located lens for access into Located things #134

Merged
merged 1 commit into from
Nov 2, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Diagrams/Located.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

module Diagrams.Located
( Located
, at, viewLoc, unLoc, loc, mapLoc
, at, viewLoc, unLoc, loc, mapLoc, located
)
where

import Control.Lens (Lens)
import Data.AffineSpace
import Data.Functor ((<$>))
import Data.VectorSpace

import Diagrams.Core
Expand Down Expand Up @@ -83,6 +85,10 @@ viewLoc (Loc p a) = (p,a)
mapLoc :: (V a ~ V b) => (a -> b) -> Located a -> Located b
mapLoc f (Loc p a) = Loc p (f a)

-- | A lens giving access to the object within a 'Located' wrapper.
located :: (V a ~ V a') => Lens (Located a) (Located a') a a'
located f (Loc p a) = Loc p <$> f a

deriving instance (Eq (V a), Eq a ) => Eq (Located a)
deriving instance (Ord (V a), Ord a ) => Ord (Located a)
deriving instance (Show (V a), Show a) => Show (Located a)
Expand Down