Skip to content

Commit

Permalink
rename fold
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellussiegburg committed Oct 10, 2024
1 parent 048e1e3 commit 21206e9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion output-blocks/output-blocks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: output-blocks
version: 0.3.0.2
version: 0.4
build-type: Simple

library
Expand Down
2 changes: 1 addition & 1 deletion output-blocks/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: output-blocks
version: 0.3.0.2
version: 0.4
extra-source-files: [ ]
build-tools: [ ]
ghc-options:
Expand Down
18 changes: 12 additions & 6 deletions output-blocks/src/Control/OutputCapable/Blocks/Generic/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ or for converting the type of 'GenericOutputCapable'.
-}
module Control.OutputCapable.Blocks.Generic.Type
( GenericOutput (..)
, foldrOutput
, foldMapOutputBy
, getOutputSequence
, getOutputSequenceAndResult
, getOutputSequenceWithRating
Expand Down Expand Up @@ -195,13 +195,15 @@ getOutputSequenceAndResult language lm = second unbox <$>

{-|
A right fold with the possibility to inspect every node.
@since: 0.4
-}
foldrOutput
foldMapOutputBy
:: (a -> a -> a)
-> (GenericOutput language element -> a)
-> GenericOutput language element
-> a
foldrOutput f evaluate x = case x of
foldMapOutputBy f evaluate x = case x of
Assertion _ xs -> foldr (f . descend) (evaluate x) xs
Image {} -> evaluate x
Images {} -> evaluate x
Expand All @@ -219,13 +221,15 @@ foldrOutput f evaluate x = case x of
Translated {} -> evaluate x
Special {} -> evaluate x
where
descend = foldrOutput f evaluate
descend = foldMapOutputBy f evaluate

{-|
Checks whether any refusal exists within the given 'GenericOutput'.
@since: 0.3.0.1
-}
withRefusal :: (element -> Bool) -> GenericOutput language element -> Bool
withRefusal checkSpecial = foldrOutput (||) $ \case
withRefusal checkSpecial = foldMapOutputBy (||) $ \case
Assertion False _ -> True
Assertion True _ -> False
Image {} -> False
Expand All @@ -242,6 +246,8 @@ withRefusal checkSpecial = foldrOutput (||) $ \case

{-|
Inspects translations provided the given inspect and combining functions.
@since: 0.3.0.1
-}
inspectTranslations
:: (element -> a)
Expand All @@ -250,7 +256,7 @@ inspectTranslations
-> a
-> GenericOutput language element
-> a
inspectTranslations inspectSpecial inspectTranslation f z = foldrOutput f $ \case
inspectTranslations inspectSpecial inspectTranslation f z = foldMapOutputBy f $ \case
Assertion {} -> z
Image {} -> z
Images {} -> z
Expand Down
16 changes: 12 additions & 4 deletions output-blocks/src/Control/OutputCapable/Blocks/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Control.OutputCapable.Blocks.Type (
-- ** for 'SpecialOutput'
type SpecialOutput,
checkTranslations,
foldrOutput,
foldMapOutputBy,
getSpecialOutputSequence,
getSpecialOutputSequenceWithRating,
specialToOutputCapable,
Expand All @@ -41,7 +41,7 @@ module Control.OutputCapable.Blocks.Type (
) where

import qualified Control.OutputCapable.Blocks.Generic.Type as Generic (
foldrOutput,
foldMapOutputBy,
getOutputSequence,
getOutputSequenceWithRating,
inspectTranslations,
Expand Down Expand Up @@ -125,22 +125,28 @@ specialToOutputCapable = Generic.toOutputCapable

{-|
A right fold with the possibility to inspect every node.
@since: 0.4
-}
foldrOutput
foldMapOutputBy
:: (a -> a -> a)
-> (SpecialOutput element -> a)
-> SpecialOutput element
-> a
foldrOutput = Generic.foldrOutput
foldMapOutputBy = Generic.foldMapOutputBy

{-|
Checks whether any refusal exists within the given 'GenericOutput'.
@since: 0.3.0.1
-}
withRefusal :: (element -> Bool) -> SpecialOutput element -> Bool
withRefusal = Generic.withRefusal

{-|
Checks a 'Map' for missing translations and reports those as list.
@since: 0.3.0.2
-}
checkTranslation :: Map Language String -> [String]
checkTranslation xs =
Expand All @@ -149,6 +155,8 @@ checkTranslation xs =

{-|
Checks 'SpecialOutput' for missing translations.
@since: 0.3.0.1
-}
checkTranslations
:: (element -> [String])
Expand Down

0 comments on commit 21206e9

Please sign in to comment.