stackctl-1.5.0.1
Safe HaskellSafe-Inferred
LanguageHaskell2010

Stackctl.OneOrListOf

Synopsis

Documentation

data OneOrListOf a Source #

Type representing one a or a list of a

This type is isomorphic both NonEmpty a and Either a [a]. Its primary use-case is to parse Yaml (through its FromJSON) where users may specify a list of values, but specifying a single value is worth supporting, typically for backwards-compatibility:

something:
  field:
    - one
    - two

something:
  field: one # => should be treated like field: [one]

The Foldable instance should be used to treat the value like a list, such as extracting it directly via toList.

Implementation note: this type preserves the form in which it was decoded (in other words, it's not a newtype over one of the isomorphic types mentioned above), so that we can encode it back out in the same format.

Instances

Instances details
Foldable OneOrListOf Source # 
Instance details

Defined in Stackctl.OneOrListOf

Methods

fold :: Monoid m => OneOrListOf m -> m #

foldMap :: Monoid m => (a -> m) -> OneOrListOf a -> m #

foldMap' :: Monoid m => (a -> m) -> OneOrListOf a -> m #

foldr :: (a -> b -> b) -> b -> OneOrListOf a -> b #

foldr' :: (a -> b -> b) -> b -> OneOrListOf a -> b #

foldl :: (b -> a -> b) -> b -> OneOrListOf a -> b #

foldl' :: (b -> a -> b) -> b -> OneOrListOf a -> b #

foldr1 :: (a -> a -> a) -> OneOrListOf a -> a #

foldl1 :: (a -> a -> a) -> OneOrListOf a -> a #

toList :: OneOrListOf a -> [a] #

null :: OneOrListOf a -> Bool #

length :: OneOrListOf a -> Int #

elem :: Eq a => a -> OneOrListOf a -> Bool #

maximum :: Ord a => OneOrListOf a -> a #

minimum :: Ord a => OneOrListOf a -> a #

sum :: Num a => OneOrListOf a -> a #

product :: Num a => OneOrListOf a -> a #

FromJSON a => FromJSON (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

ToJSON a => ToJSON (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

Semigroup (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

Generic (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

Associated Types

type Rep (OneOrListOf a) :: Type -> Type #

Methods

from :: OneOrListOf a -> Rep (OneOrListOf a) x #

to :: Rep (OneOrListOf a) x -> OneOrListOf a #

Show a => Show (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

Eq a => Eq (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

type Rep (OneOrListOf a) Source # 
Instance details

Defined in Stackctl.OneOrListOf

type Rep (OneOrListOf a) = D1 ('MetaData "OneOrListOf" "Stackctl.OneOrListOf" "stackctl-1.5.0.1-A2c4YboayP8CnSSTFojgw3" 'False) (C1 ('MetaCons "One" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "List" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a])))