Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data OneOrListOf a
- fromList :: [a] -> OneOrListOf a
Documentation
data OneOrListOf a Source #
Type representing one a
or a list of a
This type is isomorphic both
and NonEmpty
a
. Its primary
use-case is to parse Yaml (through its Either
a [a]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
fromList :: [a] -> OneOrListOf a Source #