-
Notifications
You must be signed in to change notification settings - Fork 1
/
when.js
51 lines (37 loc) · 777 Bytes
/
when.js
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
export function base_when (pred, fn_true, fn_false)
{
return (...args) =>
{
if (pred(...args))
{
return fn_true(...args)
}
else
{
return fn_false(...args)
}
}
}
import Same from '../lib/Same'
export default function when (pred, fn_false_default = Same)
{
return (fn_true, fn_false = fn_false_default) =>
{
return base_when(pred, fn_true, fn_false)
}
}
import Fin from '../lib/Fin'
export var when_data = when(is_data)
export var when_end = when(is_end)
export var when_data_all = when((...values) => (! values.some(is_end)), Fin)
import End from '../lib/End'
function is_end (value)
{
return value === End
}
function is_data (value)
{
if (value === End) { return false }
if (value instanceof Error) { return false }
return true
}