Safe Haskell | None |
---|
- data Separated s a
- type Separated' x = Separated x x
- data Separated1 a s
- type Separated1' x = Separated1 x x
- data FlipSeparated a s
- type FlipSeparated' x = FlipSeparated x x
- data FlipSeparated1 s a
- type FlipSeparated1' x = FlipSeparated1 x x
- class (f ~ SeparatedConsF g, g ~ SeparatedConsG f) => SeparatedCons f g where
- type SeparatedConsF g :: * -> * -> *
- type SeparatedConsG f :: * -> * -> *
- (+:) :: a -> f s a -> g a s
- class (f ~ FlipSeparatedConsF g, g ~ FlipSeparatedConsG f) => FlipSeparatedCons f g where
- type FlipSeparatedConsF g :: * -> * -> *
- type FlipSeparatedConsG f :: * -> * -> *
- (+.) :: s -> f s a -> g a s
- (++:) :: Separated1 s a -> Separated1 a s -> Separated s a
- (*+:) :: Separated s a -> Separated1 s a -> Separated1 s a
- (**:) :: Separated1 a s -> Separated s a -> Separated1 a s
- empty :: Separated a s
- single :: a -> Separated1 a s
- (+:.) :: a -> s -> Separated a s
- fempty :: FlipSeparated a s
- allValues :: Separated' a -> [a]
- allValues1 :: Separated1' a -> NonEmpty a
- separatedValues :: Separated s a -> [a]
- separated1Values :: Separated1 a s -> NonEmpty a
- separators :: Separated s a -> [s]
- separators1 :: Separated1 a s -> [s]
- separatedIso :: Iso' [(s, a)] (Separated s a)
- separatedSwap :: Iso' (Separated s a) (Separated a s)
- separated1Iso :: Iso' (a, [(s, a)]) (Separated1 a s)
- shift :: Iso' (Separated1 a s) ([(a, s)], a)
- separated1Head :: Lens' (Separated1 a s) a
- separated1Tail :: Lens' (Separated1 a s) (Separated s a)
- flipSeparatedIso :: Iso' (FlipSeparated a s) (Separated s a)
- flipSeparatedSwapIso :: Iso' (FlipSeparated a s) (Separated a s)
- flipSeparated1Iso :: Iso' (FlipSeparated1 s a) (Separated1 a s)
- separatedWith :: Alternative f => f s -> f a -> f (Maybe (Separated1 s a))
- separatedWith1 :: Alternative f => f a -> f s -> f (Separated1 a s)
Data types
A data type representing a list of pairs of separator and element values.
SeparatedCons Separated1 Separated | |
SeparatedCons Separated Separated1 | |
Functor (Separated s) | Map across a fmap id (x :: Separated Int String) == x fmap (+1) (a +: b +: empty) == a +: (1+b) +: empty |
Monoid s => Applicative (Separated s) | Applies functions with element values, using a zipping operation, appending separators. The identity operation is an infinite list of the empty separator and the given element value.
|
Semigroup s => Apply (Separated s) | Applies functions with element values, using a zipping operation, appending separators.
|
(Eq s, Eq a) => Eq (Separated s a) | |
(Ord s, Ord a) => Ord (Separated s a) | |
(Show s, Show a) => Show (Separated s a) |
type Separated' x = Separated x xSource
data Separated1 a s Source
A data type representing element values interspersed with a separator.
There is one fewer separator values (s
) than there are element values (a
). There is at least one element value.
SeparatedCons Separated1 Separated | |
SeparatedCons Separated Separated1 | |
Functor (Separated1 a) | Map across a
fmap id (x :: Separated1 Int String) == x fmap (+1) (single x) == single x |
Monoid a => Applicative (Separated1 a) | Applies functions with separator values, using a zipping operation, appending elements. The identity operation is an infinite list of the empty element and the given separator value.
|
Semigroup a => Apply (Separated1 a) | Applies functions with separator values, using a zipping operation, appending elements.
|
(Eq a, Eq s) => Eq (Separated1 a s) | |
(Ord a, Ord s) => Ord (Separated1 a s) | |
(Show a, Show s) => Show (Separated1 a s) |
type Separated1' x = Separated1 x xSource
data FlipSeparated a s Source
A data type representing a list of pairs of separator and element values.
Isomorphic to Separated
with the type constructor flipped.
FlipSeparatedCons FlipSeparated1 FlipSeparated | |
FlipSeparatedCons FlipSeparated FlipSeparated1 | |
Functor (FlipSeparated a) | Map across a fmap id (x :: FlipSeparated Int String) == x fmap (+1) (a +. b +. fempty) == (1+a) +. b +. fempty |
Monoid a => Applicative (FlipSeparated a) | Applies functions with separator values, using a zipping operation, appending elements. The identity operation is an infinite list of the empty element and the given separator value.
|
Semigroup a => Apply (FlipSeparated a) | Applies functions with separator values, using a zipping operation, appending elements.
|
(Eq a, Eq s) => Eq (FlipSeparated a s) | |
(Ord a, Ord s) => Ord (FlipSeparated a s) | |
(Show a, Show s) => Show (FlipSeparated a s) |
type FlipSeparated' x = FlipSeparated x xSource
data FlipSeparated1 s a Source
A data type representing element values interspersed with a separator.
Isomorphic to Separated1
with the type constructor flipped.
There is one fewer separator values (s
) than there are element values (a
). There is at least one element value.
FlipSeparatedCons FlipSeparated1 FlipSeparated | |
FlipSeparatedCons FlipSeparated FlipSeparated1 | |
Functor (FlipSeparated1 s) | |
Monoid s => Applicative (FlipSeparated1 s) | Applies functions with element values, using a zipping operation, appending separators. The identity operation is an infinite list of the empty separator and the given element value.
|
Semigroup s => Apply (FlipSeparated1 s) | Applies functions with element values, using a zipping operation, appending separators.
|
(Eq s, Eq a) => Eq (FlipSeparated1 s a) | |
(Ord s, Ord a) => Ord (FlipSeparated1 s a) | |
(Show s, Show a) => Show (FlipSeparated1 s a) |
type FlipSeparated1' x = FlipSeparated1 x xSource
Inserting elements
class (f ~ SeparatedConsF g, g ~ SeparatedConsG f) => SeparatedCons f g whereSource
Prepend a value to a separated-like structure.
>>>
'z' +: empty
['z']
>>>
9 +: 'z' +: empty
[9,'z']
type SeparatedConsF g :: * -> * -> *Source
type SeparatedConsG f :: * -> * -> *Source
class (f ~ FlipSeparatedConsF g, g ~ FlipSeparatedConsG f) => FlipSeparatedCons f g whereSource
Prepend a value to a flipped separated-like structure.
>>>
'z' +. fempty
['z']
>>>
9 +. 'z' +. fempty
[9,'z']
type FlipSeparatedConsF g :: * -> * -> *Source
type FlipSeparatedConsG f :: * -> * -> *Source
(++:) :: Separated1 s a -> Separated1 a s -> Separated s aSource
Append two lists of separated values to produce a list of pairs of separator and element values.
>>>
single 7 ++: single 'a'
[7,'a']
a
+: single 7 ++: single b
[a
,7,b
]
a +: (b ++: c) == (a +: b) *+: c
(*+:) :: Separated s a -> Separated1 s a -> Separated1 s aSource
Append element values interspersed with a separator to a list of pairs of separator and element values.
>>>
empty *+: single 7
[7]
>>>
empty *+: 6 +: 'x' +: single 7
[6,'x',7]
>>>
'w' +: empty *+: 6 +: 'x' +: single 7
['w',6,'x',7]
(**:) :: Separated1 a s -> Separated s a -> Separated1 a sSource
Append a list of pairs of separator and element values to element values interspersed with a separator.
>>>
single 7 **: empty
[7]
>>>
single 6 **: 'x' +: 7 +: empty
[6,'x',7]
>>>
'w' +: single 6 **: 'x' +: 7 +: empty
['w',6,'x',7]
Constructing data types
An empty list of pairs of separator and element values.
>>>
empty
[]
empty *+: x == x
x **: empty == x
single :: a -> Separated1 a sSource
Zero element values interspersed with one element.
>>>
single 4
[4]
single x ^. separated1Tail == empty
(+:.) :: a -> s -> Separated a sSource
One element and one separator.
>>>
7 +:. "abc"
[7,"abc"]
>>>
7 +: "abc" +: 8 +:. "def"
[7,"abc",8,"def"]
fempty :: FlipSeparated a sSource
Extracting values from data types
allValues :: Separated' a -> [a]Source
Extract all values, where the separator and element are the same type.
>>>
allValues empty
[]
>>>
allValues (1 +: 2 +: 3 +: 4 +: empty)
[1,2,3,4]
allValues1 :: Separated1' a -> NonEmpty aSource
Extract all values, where the separator and element are the same type.
>>>
allValues1 (single 7)
7 :| []
>>>
allValues1 (1 +: 2 +: 3 +: empty)
1 :| [2,3]
separatedValues :: Separated s a -> [a]Source
Return all element values in a list of pairs of element and separator values.
>>>
separatedValues empty
[]
>>>
separatedValues ('x' +: 2 +: empty)
[2]
separated1Values :: Separated1 a s -> NonEmpty aSource
Return all element values.
>>>
separated1Values (single 8)
8 :| []
>>>
separated1Values (7 +: 'a' +: single 8)
7 :| [8]
let h :| _ = separated1Values (single x) in h == (x :: Int)
let _ :| t = separated1Values (d +: e +: single x) in t == fmap fst [e]
separators :: Separated s a -> [s]Source
Return all separator values.
>>>
separators empty
[]
>>>
separators ('x' +: 2 +: empty)
"x"
separators1 :: Separated1 a s -> [s]Source
Return all separator values.
>>>
separators ('a' +: single 7)
"a"
>>>
separators ('a' +: 6 +:'b' +: single 7)
"ab"
separators (a +: single x) == [a]
Lenses and isomorphisms
separatedIso :: Iso' [(s, a)] (Separated s a)Source
The isomorphism to a list of pairs of element and separator values.
>>>
separatedIso # empty
[]
>>>
separatedIso # ('x' +: 6 +: empty)
[('x',6)]
>>>
[] ^. separatedIso
[]
>>>
[(6, [])] ^. separatedIso
[6,[]]
separatedSwap :: Iso' (Separated s a) (Separated a s)Source
The isomorphism that swaps elements with their separators.
>>>
separatedSwap # empty
[]
>>>
separatedSwap # ('x' +: 6 +: empty)
[6,'x']
>>>
empty ^. separatedSwap
[]
>>>
('x' +: 6 +: empty) ^. separatedSwap
[6,'x']
separated1Iso :: Iso' (a, [(s, a)]) (Separated1 a s)Source
The isomorphism to element values interspersed with a separator.
>>>
separated1Iso # (single 6)
(6,[])
>>>
separated1Iso # (5 +: 'x' +: single 6)
(5,[('x',6)])
>>>
(6, []) ^. separated1Iso
[6]
>>>
(5, [('x', 6)]) ^. separated1Iso
[5,'x',6]
shift :: Iso' (Separated1 a s) ([(a, s)], a)Source
The isomorphism that shuffles the elements and separators one position.
>>>
shift # ([], 6)
[6]
>>>
shift # ([(5, 'x')], 6)
[5,'x',6]
>>>
single 6 ^. shift
([],6)
>>>
(5 +: 'x' +: single 6) ^. shift
([(5,'x')],6)
separated1Head :: Lens' (Separated1 a s) aSource
A lens on the first element value.
>>>
single 7 ^. separated1Head
7
single x ^. separated1Head == (x :: Int)
separated1Tail :: Lens' (Separated1 a s) (Separated s a)Source
A lens on the tail.
d +: e +: single x ^. separated1Tail == e +: x +: empty
flipSeparatedIso :: Iso' (FlipSeparated a s) (Separated s a)Source
The isomorphism to a Separator
.
>>>
flipSeparatedIso # empty
[]
>>>
flipSeparatedIso # ('x' +: 6 +: empty)
['x',6]
>>>
[] ^. separatedIso . from flipSeparatedIso
[]
>>>
[(6, [])] ^. separatedIso . from flipSeparatedIso
[6,[]]
flipSeparatedSwapIso :: Iso' (FlipSeparated a s) (Separated a s)Source
flipSeparated1Iso :: Iso' (FlipSeparated1 s a) (Separated1 a s)Source
The isomorphism to a Separated1
.
>>>
flipSeparated1Iso # (single 6)
[6]
>>>
flipSeparated1Iso # (5 +: 'x' +: single 6)
[5,'x',6]
>>>
(6 +: empty) ^. from flipSeparated1Iso
[6]
>>>
(5 +: 'x' +: 6 +: empty) ^. from flipSeparated1Iso
[5,'x',6]
Alternating combinators
separatedWith :: Alternative f => f s -> f a -> f (Maybe (Separated1 s a))Source
Effectful separation with failure represented by Nothing
.
>>>
separatedWith Nothing Nothing
Just Nothing
>>>
separatedWith Nothing (Just 7)
Just Nothing
>>>
separatedWith (Just 'x') Nothing
Just (Just ['x'])
>>>
separatedWith [] []
[Nothing]
>>>
separatedWith [] [1,2,3]
[Nothing]
>>>
separatedWith [1,2,3] []
[Just [1],Just [2],Just [3],Nothing]
separatedWith1 :: Alternative f => f a -> f s -> f (Separated1 a s)Source
Effectful separation.
>>>
separatedWith1 Nothing Nothing
Nothing
>>>
separatedWith1 Nothing (Just 7)
Nothing
>>>
separatedWith1 (Just 'x') Nothing
Just ['x']
>>>
separatedWith1 [] []
[]
>>>
separatedWith1 [] [1,2,3]
[]
>>>
separatedWith1 [1,2,3] []
[[1],[2],[3]]