-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ls
65 lines (32 loc) · 1.02 KB
/
main.ls
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
flyd = require "flyd"
{is-postive-number,inform} = require "./utils.js"
wait = (t,f) -> setTimeout f,t
main = (time,input) ->
local = {}
..vals = []
..waiting = false
flyd.combine do
(input,self) ->
local.vals.push input!
if not local.waiting # not waiting, set up wait
local.waiting = true
<- wait time
local.waiting = false # no more waits left
self local.vals
local.vals = []
return void
[input]
# returns null in case you want to wrap in a maybe monad not done by default for portability.
validate-input = (time,stream) ->
if not (flyd.isStream stream)
inform.not-flyd-stream!
return null
[is-correct,data] = is-postive-number time
if not is-correct
inform.invalid-value-for-time data
return null
main time,stream
curried-validate-input = flyd.curryN 2,validate-input
curried-validate-input.default = curried-validate-input
curried-validate-input.esModule = true
module.exports = curried-validate-input