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