Skip to content

Commit

Permalink
add more specialised version of getOutputsequenceAndResult (#24)
Browse files Browse the repository at this point in the history
* add more specialized version of `getOutputsequenceAndResult`

* bring docs for new function in line with others

* remove unfitting part of docs

* more in line with other module

* of course the other way around

* rename functions for consistency

---------

Co-authored-by: Janis Voigtländer <[email protected]>
  • Loading branch information
patritzenfeld and jvoigtlaender authored Feb 26, 2025
1 parent 7a48d09 commit c8b60a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
12 changes: 6 additions & 6 deletions output-blocks/src/Control/OutputCapable/Blocks/Generic/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Control.OutputCapable.Blocks.Generic.Type
( GenericOutput (..)
, foldMapOutputBy
, getOutputSequence
, getOutputSequenceAndResult
, getOutputSequenceWithResult
, getOutputSequenceWithRating
, inspectTranslations
, toOutputCapable
Expand Down Expand Up @@ -154,12 +154,12 @@ getOutputSequence
=> language
-> GenericLangM language (GenericReportT language (GenericOutput language element) m) ()
-> m [GenericOutput language element]
getOutputSequence f = (snd <$>) . getOutputSequenceAndResult f
getOutputSequence f = (snd <$>) . getOutputSequenceWithResult f



{-|
More concretely typed alias of 'getOutputSequenceAndResult'
More concretely typed alias of 'getOutputSequenceWithResult'
Converts graded 'GenericOutputCapable' value using 'GenericOutput'
into a rating and a list of 'GenericOutput'
Expand All @@ -169,7 +169,7 @@ getOutputSequenceWithRating
=> language
-> GenericLangM language (GenericReportT language (GenericOutput language element) m) Rational
-> m (Maybe Rational, [GenericOutput language element])
getOutputSequenceWithRating = getOutputSequenceAndResult
getOutputSequenceWithRating = getOutputSequenceWithResult


{-|
Expand All @@ -180,12 +180,12 @@ Consider using 'getOutputSequenceWithRating'
or even more specific versions of 'Control.OutputCapable.Blocks.Type'
in order to get better error messages on implementation errors.
-}
getOutputSequenceAndResult
getOutputSequenceWithResult
:: Functor m
=> language
-> GenericLangM language (GenericReportT language (GenericOutput language element) m) a
-> m (Maybe a, [GenericOutput language element])
getOutputSequenceAndResult language lm = second unbox <$>
getOutputSequenceWithResult language lm = second unbox <$>
runLangMReportMultiLang (Paragraph []) gather ($ language) lm
where
gather (Paragraph xs) x = Paragraph (xs ++ [x])
Expand Down
18 changes: 17 additions & 1 deletion output-blocks/src/Control/OutputCapable/Blocks/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Control.OutputCapable.Blocks.Type (
type Output,
getOutputSequence,
getOutputSequenceWithRating,
getOutputSequenceWithResult,
toOutputCapable,
-- ** for 'SpecialOutput'
type SpecialOutput,
Expand All @@ -43,6 +44,7 @@ module Control.OutputCapable.Blocks.Type (
import qualified Control.OutputCapable.Blocks.Generic.Type as Generic (
foldMapOutputBy,
getOutputSequence,
getOutputSequenceWithResult,
getOutputSequenceWithRating,
inspectTranslations,
toOutputCapable,
Expand All @@ -54,6 +56,7 @@ import qualified Data.Map as M (keys)
import Control.OutputCapable.Blocks.Generic.Type (GenericOutput (..))
import Control.OutputCapable.Blocks (
LangM,
LangM',
Language (English),
OutputCapable,
Rated,
Expand Down Expand Up @@ -84,7 +87,20 @@ getOutputSequenceWithRating
:: Functor m
=> Rated (ReportT Output m)
-> m (Maybe Rational, [Output])
getOutputSequenceWithRating = Generic.getOutputSequenceWithRating English
getOutputSequenceWithRating = getOutputSequenceWithResult

{-|
Converts 'OutputCapable' value using 'GenericOutput'
into a result and a list of 'Output'
Consider using 'getOutputSequenceWithRating'
in order to get better error messages on implementation errors.
-}
getOutputSequenceWithResult
:: Functor m
=> LangM' (ReportT Output m) a
-> m (Maybe a, [Output])
getOutputSequenceWithResult = Generic.getOutputSequenceWithResult English

{- |
Convert a list of 'Output' into any instance of 'OutputCapable'
Expand Down

0 comments on commit c8b60a9

Please sign in to comment.