27 lines
805 B
Text
27 lines
805 B
Text
module Utils where
|
|
|
|
import Prelude (($), (+), (<>), (==))
|
|
import Data.Array as A
|
|
import Data.Maybe (Maybe(..), fromMaybe)
|
|
import Data.Tuple (Tuple(..))
|
|
|
|
attach_id :: forall a. Int -> Array a -> Array (Tuple Int a)
|
|
attach_id _ [] = []
|
|
attach_id i arr = case A.head arr of
|
|
Just x -> [Tuple i x] <> attach_id (i + 1) (fromMaybe [] $ A.tail arr)
|
|
Nothing -> []
|
|
|
|
remove_id :: forall a. Int -> Array (Tuple Int a) -> Array a
|
|
remove_id _ [] = []
|
|
remove_id i arr = case A.head arr of
|
|
Just (Tuple n x) -> if i == n
|
|
then remove_id i (fromMaybe [] $ A.tail arr)
|
|
else [x] <> remove_id i (fromMaybe [] $ A.tail arr)
|
|
Nothing -> []
|
|
|
|
id :: forall a. a -> a
|
|
id x = x
|
|
|
|
not_empty_string :: String -> Maybe String
|
|
not_empty_string "" = Nothing
|
|
not_empty_string v = Just v
|