-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
57 lines (46 loc) · 1.43 KB
/
stream.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
// Package stream provides WDTE functions for manipulating streams of
// data.
package stream
import (
"github.com/DeedleFake/wdte"
"github.com/DeedleFake/wdte/std"
)
// A Stream is a type of function that can yield successive values.
type Stream interface {
wdte.Func
// Next returns the next value and true, or an undefined value and
// false if the stream is empty.
Next(frame wdte.Frame) (wdte.Func, bool)
}
// A NextFunc wraps a Go function, making it possible to use it as a
// Stream. When called as a WDTE function, the function simply returns
// itself.
type NextFunc func(frame wdte.Frame) (wdte.Func, bool)
func (n NextFunc) Call(frame wdte.Frame, args ...wdte.Func) wdte.Func { // nolint
return n
}
func (n NextFunc) Next(frame wdte.Frame) (wdte.Func, bool) { // nolint
return n(frame)
}
func (NextFunc) String() string { // nolint
return "<stream>"
}
// Scope is a scope containing the functions in this package.
var Scope = wdte.S().Map(map[wdte.ID]wdte.Func{
"new": wdte.GoFunc(New),
"range": wdte.GoFunc(Range),
"concat": wdte.GoFunc(Concat),
"map": wdte.GoFunc(Map),
"filter": wdte.GoFunc(Filter),
"flatMap": wdte.GoFunc(FlatMap),
"enumerate": wdte.GoFunc(Enumerate),
"collect": wdte.GoFunc(Collect),
"drain": wdte.GoFunc(Drain),
"reduce": wdte.GoFunc(Reduce),
//"chain": wdte.GoFunc(Chain),
"any": wdte.GoFunc(Any),
"all": wdte.GoFunc(All),
})
func init() {
std.Register("stream", Scope)
}