~jojo/Carth

ref: db87ea9bdce9470b546bb3098f5d79a9b1023af1 Carth/src/NonEmpty.hs -rw-r--r-- 786 bytes
db87ea9bJoJo Disclaim WIP status in readme 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

module NonEmpty
    ( NonEmpty(..)
    , intersperse1
    , intercalate1
    , precalate1
    , map1
    , toList1
    , fromList1
    , nonEmpty
    )
where

import Data.Composition
import qualified Data.List.NonEmpty as NonEmpty
import Data.List.NonEmpty (NonEmpty(..), nonEmpty)

intersperse1 :: a -> NonEmpty a -> NonEmpty a
intersperse1 = NonEmpty.intersperse

intercalate1 :: [a] -> NonEmpty [a] -> [a]
intercalate1 = concat .* intersperse1

precalate1 :: [a] -> NonEmpty [a] -> [a]
precalate1 prefix = (prefix ++) . intercalate1 prefix

map1 :: (a -> b) -> NonEmpty a -> NonEmpty b
map1 = NonEmpty.map

toList1 :: [a] -> NonEmpty a
toList1 = NonEmpty.fromList

fromList1 :: NonEmpty a -> [a]
fromList1 = NonEmpty.toList