blob: a9a668d04a15e1334379d0889c6c53026b319cb9 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
----
-- base Result interface.
--
-- implemented by `Constant`, `SigStream`, and `EvtStream`.
--
-- @classmod Result
import Type from require 'alv.type'
import ancestor from require 'alv.util'
class Result
--- Result interface.
--
-- Methods that have to be implemented by `Result` implementations
-- (`Constant`, `SigStream`, `EvtStream`).
--
-- @section interface
--- return whether this Result was changed in the current tick.
-- @function dirty
-- @treturn boolean
--- create a mutable copy of this Result.
--
-- Used to insulate eval-cycles from each other.
--
-- @function fork
-- @treturn Result
__tostring: =>
if @value then
"<#{@type}#{@metatype} #{@type\pp @value}>"
else
"<#{@type}#{@metatype}>"
__inherited: (cls) => cls.__base.__tostring or= @__tostring
--- the type of this Result's value.
-- @tfield type.Type type
--- the metatype string for this Result.
--
-- one of `=` (`Constant`), `~` (`SigStream`), `!` (`EvtStream`).
--
-- @tfield string metatype
--- documentation metadata.
--
-- an optional table containing metadata for error messages and
-- documentation. The following keys are recognized:
--
-- - `name`: optional name
-- - `summary`: single-line description (markdown)
-- - `examples`: optional list of single-line code examples
-- - `description`: optional full-text description (markdown)
--
-- @tfield ?table meta
--- static functions
-- @section static
--- construct a new Result.
--
-- @classmethod
-- @tparam type.Type type the type
-- @tparam ?table meta the `meta` table
new: (@type, @meta={}) =>
assert @type and (ancestor @type.__class) == Type, "not a type: #{@type}"
{
:Result
__eq: (a, b) ->
a.type == b.type and a.type\eq a.value, b.value
}
|