aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/comonad/cofree.lux
blob: 5ac04557f45da44c39052dacc0cc81f035987678 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(.using
 [library
  [lux "*"
   ["_" test (.only Test)]
   [abstract
    [functor (.only Functor)]
    [comonad (.only CoMonad)]
    [\\specification
     ["$[0]" functor (.only Injection Comparison)]
     ["$[0]" comonad]]]
   [control
    ["//" continuation]]
   [data
    [collection
     ["[0]" list]
     ["[0]" stream (.only Stream) ("[1]#[0]" comonad)]]]
   [math
    ["[0]" random]]]]
 [\\library
  ["[0]" /]])

(def: (injection value)
  (Injection (/.CoFree Stream))
  [value (stream#each injection (stream.repeated value))])

(def: (interpret [head tail])
  (All (_ a) (-> (/.CoFree Stream a) (Stream a)))
  (|> tail
      (stream#each (# (/.comonad stream.functor) out))
      [head]
      //.pending))

(def: comparison
  (Comparison (/.CoFree Stream))
  (function (_ == left right)
    (# (list.equivalence ==) =
       (stream.first 100 (..interpret left))
       (stream.first 100 (..interpret right)))))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.CoFree])
      (all _.and
           (_.for [/.functor]
                  ($functor.spec ..injection ..comparison (is (Functor (/.CoFree Stream))
                                                              (/.functor stream.functor))))
           (_.for [/.comonad]
                  ($comonad.spec ..injection ..comparison (is (CoMonad (/.CoFree Stream))
                                                              (/.comonad stream.functor))))
           )))