module Fresnel.List.NonEmpty
( -- * Optics
  nonEmpty_
, uncons_
, head_
, tail_
) where

import qualified Data.List.NonEmpty as NE
import           Fresnel.Iso (Iso, from, iso)
import           Fresnel.Lens (Lens')
import           Fresnel.Tuple (fst_, snd_)

-- Optics

nonEmpty_ :: Iso [a] [b] (Maybe (NE.NonEmpty a)) (Maybe (NE.NonEmpty b))
nonEmpty_ :: forall a b (p :: * -> * -> *).
IsIso p =>
Optic p [a] [b] (Maybe (NonEmpty a)) (Maybe (NonEmpty b))
nonEmpty_ = ([a] -> Maybe (NonEmpty a))
-> (Maybe (NonEmpty b) -> [b])
-> Iso [a] [b] (Maybe (NonEmpty a)) (Maybe (NonEmpty b))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty ((NonEmpty b -> [b]) -> Maybe (NonEmpty b) -> [b]
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap NonEmpty b -> [b]
forall a. NonEmpty a -> [a]
NE.toList)

uncons_ :: Iso (NE.NonEmpty a) (NE.NonEmpty b) (a, Maybe (NE.NonEmpty a)) (b, Maybe (NE.NonEmpty b))
uncons_ :: forall a b (p :: * -> * -> *).
IsIso p =>
Optic
  p
  (NonEmpty a)
  (NonEmpty b)
  (a, Maybe (NonEmpty a))
  (b, Maybe (NonEmpty b))
uncons_ = (NonEmpty a -> (a, Maybe (NonEmpty a)))
-> ((b, Maybe (NonEmpty b)) -> NonEmpty b)
-> Iso
     (NonEmpty a)
     (NonEmpty b)
     (a, Maybe (NonEmpty a))
     (b, Maybe (NonEmpty b))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso NonEmpty a -> (a, Maybe (NonEmpty a))
forall a. NonEmpty a -> (a, Maybe (NonEmpty a))
NE.uncons ((b -> [b] -> NonEmpty b) -> (b, [b]) -> NonEmpty b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry b -> [b] -> NonEmpty b
forall a. a -> [a] -> NonEmpty a
(NE.:|) ((b, [b]) -> NonEmpty b)
-> ((b, Maybe (NonEmpty b)) -> (b, [b]))
-> (b, Maybe (NonEmpty b))
-> NonEmpty b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (NonEmpty b) -> [b]) -> (b, Maybe (NonEmpty b)) -> (b, [b])
forall a b. (a -> b) -> (b, a) -> (b, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((NonEmpty b -> [b]) -> Maybe (NonEmpty b) -> [b]
forall m a. Monoid m => (a -> m) -> Maybe a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap NonEmpty b -> [b]
forall a. NonEmpty a -> [a]
NE.toList))

head_ :: Lens' (NE.NonEmpty a) a
head_ :: forall a (p :: * -> * -> *).
IsLens p =>
Optic p (NonEmpty a) (NonEmpty a) a a
head_ = Optic
  p
  (NonEmpty a)
  (NonEmpty a)
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
forall a b (p :: * -> * -> *).
IsIso p =>
Optic
  p
  (NonEmpty a)
  (NonEmpty b)
  (a, Maybe (NonEmpty a))
  (b, Maybe (NonEmpty b))
uncons_Optic
  p
  (NonEmpty a)
  (NonEmpty a)
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
-> (p a a -> p (a, Maybe (NonEmpty a)) (a, Maybe (NonEmpty a)))
-> p a a
-> p (NonEmpty a) (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.p a a -> p (a, Maybe (NonEmpty a)) (a, Maybe (NonEmpty a))
forall a b a' (p :: * -> * -> *).
IsLens p =>
Optic p (a, b) (a', b) a a'
fst_

tail_ :: Lens' (NE.NonEmpty a) [a]
tail_ :: forall a (p :: * -> * -> *).
IsLens p =>
Optic p (NonEmpty a) (NonEmpty a) [a] [a]
tail_ = Optic
  p
  (NonEmpty a)
  (NonEmpty a)
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
forall a b (p :: * -> * -> *).
IsIso p =>
Optic
  p
  (NonEmpty a)
  (NonEmpty b)
  (a, Maybe (NonEmpty a))
  (b, Maybe (NonEmpty b))
uncons_Optic
  p
  (NonEmpty a)
  (NonEmpty a)
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
-> (p [a] [a] -> p (a, Maybe (NonEmpty a)) (a, Maybe (NonEmpty a)))
-> p [a] [a]
-> p (NonEmpty a) (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Optic
  p
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
  (Maybe (NonEmpty a))
  (Maybe (NonEmpty a))
forall a b b' (p :: * -> * -> *).
IsLens p =>
Optic p (a, b) (a, b') b b'
snd_Optic
  p
  (a, Maybe (NonEmpty a))
  (a, Maybe (NonEmpty a))
  (Maybe (NonEmpty a))
  (Maybe (NonEmpty a))
-> (p [a] [a] -> p (Maybe (NonEmpty a)) (Maybe (NonEmpty a)))
-> p [a] [a]
-> p (a, Maybe (NonEmpty a)) (a, Maybe (NonEmpty a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Iso [a] [a] (Maybe (NonEmpty a)) (Maybe (NonEmpty a))
-> Iso (Maybe (NonEmpty a)) (Maybe (NonEmpty a)) [a] [a]
forall s t a b. Iso s t a b -> Iso b a t s
from Optic p [a] [a] (Maybe (NonEmpty a)) (Maybe (NonEmpty a))
forall a b (p :: * -> * -> *).
IsIso p =>
Optic p [a] [b] (Maybe (NonEmpty a)) (Maybe (NonEmpty b))
Iso [a] [a] (Maybe (NonEmpty a)) (Maybe (NonEmpty a))
nonEmpty_