aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/abstract/enum.lux
blob: 5bbb7df38eaebfafbe6a6714abbb86ff38fc73c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(.module:
  [lux #*]
  [//
   ["." order]])

(signature: #export (Enum e)
  {#.doc "Enumerable types, with a notion of moving forward and backwards through a type's instances."}
  (: (order.Order e) &order)
  (: (-> e e) succ)
  (: (-> e e) pred))

(def: (range' <= succ from to)
  (All [a] (-> (-> a a Bit) (-> a a) a a (List a)))
  (if (<= to from)
    (#.Cons from (range' <= succ (succ from) to))
    #.Nil))

(def: #export (range (^open ".") from to)
  {#.doc "An inclusive [from, to] range of values."}
  (All [a] (-> (Enum a) a a (List a)))
  (range' <= succ from to))