-
Notifications
You must be signed in to change notification settings - Fork 1
/
map8.go
77 lines (67 loc) · 2.43 KB
/
map8.go
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
73
74
75
76
77
package incr
import (
"context"
"fmt"
)
// Map8 applies a function to given input incrementals and returns
// a new incremental of the output type of that function.
func Map8[A, B, C, D, E, F, G, H, I any](scope Scope, a Incr[A], b Incr[B], c Incr[C], d Incr[D], e Incr[E], f Incr[F], g Incr[G], h Incr[H], fn func(A, B, C, D, E, F, G, H) I) Incr[I] {
return Map8Context(scope, a, b, c, d, e, f, g, h, func(_ context.Context, av A, bv B, cv C, dv D, ev E, fv F, gv G, hv H) (I, error) {
return fn(av, bv, cv, dv, ev, fv, gv, hv), nil
})
}
// Map8Context applies a function that accepts a context and returns
// an error, to given input incrementals and returns a
// new incremental of the output type of that function.
func Map8Context[A, B, C, D, E, F, G, H, I any](scope Scope, a Incr[A], b Incr[B], c Incr[C], d Incr[D], e Incr[E], f Incr[F], g Incr[G], h Incr[H], fn func(context.Context, A, B, C, D, E, F, G, H) (I, error)) Incr[I] {
return WithinScope(scope, &map8Incr[A, B, C, D, E, F, G, H, I]{
n: NewNode("map8"),
a: a,
b: b,
c: c,
d: d,
e: e,
f: f,
g: g,
h: h,
fn: fn,
parents: []INode{a, b, c, d, e, f, g, h},
})
}
var (
_ Incr[string] = (*map8Incr[int, int, int, int, int, int, int, int, string])(nil)
_ INode = (*map8Incr[int, int, int, int, int, int, int, int, string])(nil)
_ IStabilize = (*map8Incr[int, int, int, int, int, int, int, int, string])(nil)
_ fmt.Stringer = (*map8Incr[int, int, int, int, int, int, int, int, string])(nil)
)
type map8Incr[A, B, C, D, E, F, G, H, I any] struct {
n *Node
a Incr[A]
b Incr[B]
c Incr[C]
d Incr[D]
e Incr[E]
f Incr[F]
g Incr[G]
h Incr[H]
fn func(context.Context, A, B, C, D, E, F, G, H) (I, error)
val I
parents []INode
}
func (mn *map8Incr[A, B, C, D, E, F, G, H, I]) Parents() []INode {
return mn.parents
}
func (mn *map8Incr[A, B, C, D, E, F, G, H, I]) Node() *Node { return mn.n }
func (mn *map8Incr[A, B, C, D, E, F, G, H, I]) Value() I { return mn.val }
func (mn *map8Incr[A, B, C, D, E, F, G, H, I]) Stabilize(ctx context.Context) (err error) {
var val I
val, err = mn.fn(ctx, mn.a.Value(), mn.b.Value(), mn.c.Value(), mn.d.Value(), mn.e.Value(), mn.f.Value(), mn.g.Value(), mn.h.Value())
if err != nil {
return
}
mn.val = val
return nil
}
func (mn *map8Incr[A, B, C, D, E, F, G, H, I]) String() string {
return mn.n.String()
}