Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cuddle.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ library
Codec.CBOR.Cuddle.CDDL.Resolve
Codec.CBOR.Cuddle.Huddle
Codec.CBOR.Cuddle.Huddle.HuddleM
Codec.CBOR.Cuddle.Huddle.Optics
Codec.CBOR.Cuddle.Parser
Codec.CBOR.Cuddle.Pretty

Expand Down
24 changes: 24 additions & 0 deletions src/Codec/CBOR/Cuddle/Huddle/Optics.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- | Optics for mutating Huddle rules
module Codec.CBOR.Cuddle.Huddle.Optics (commentL, nameL) where

import Codec.CBOR.Cuddle.Huddle
import Data.Generics.Product (HasField' (field'))
import Data.Text qualified as T
import Optics.Core

mcommentL ::
(HasField' "description" a (Maybe T.Text)) =>
Lens a a (Maybe T.Text) (Maybe T.Text)
mcommentL = field' @"description"

-- | Traversal to the comment field of a description. Using this we can for
-- example set the comment with 'a & commentL .~ "This is a comment"'
commentL ::
(HasField' "description" a (Maybe T.Text)) =>
AffineTraversal a a T.Text T.Text
commentL = mcommentL % _Just

-- | Lens to the name of a rule (or other named entity). Using this we can
-- for example append to the name with 'a & nameL %~ (<> "_1")'
nameL :: Lens (Named a) (Named a) T.Text T.Text
nameL = field' @"name"
Loading