aboutsummaryrefslogtreecommitdiff
path: root/src/Utils/List.elm
blob: 83b11eb7652d3d453f356928c1823992811ec580 (plain)
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
module Utils.List
  ( repeat
  , splitAt
  , maybeHead
  , maybeTail
  ) where

import List

repeat : Int -> a -> List a
repeat count elem =
  if count > 0
    then
      elem :: (repeat (count - 1) elem)
    else
      []

splitAt : Int -> List a -> (List a, List a)
splitAt n xs = (List.take n xs, List.drop n xs)

maybeHead : List a -> Maybe a
maybeHead xs =
  case xs of
    x :: _ -> Just x
    _ -> Nothing

maybeTail : List a -> Maybe (List a)
maybeTail xs =
  case xs of
    _ :: tl -> Just tl
    _ -> Nothing