Skip to content

Commit 2a11246

Browse files
authored
Make Prefixed adopt pragmas of wrapped slice (#112)
1 parent 02ee7b1 commit 2a11246

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

slice.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ func (s scanSlice) Reader(shard int, deps []sliceio.Reader) sliceio.Reader {
10231023
}
10241024

10251025
type prefixSlice struct {
1026+
Pragma
10261027
Slice
10271028
prefix int
10281029
}
@@ -1037,7 +1038,11 @@ func Prefixed(slice Slice, prefix int) Slice {
10371038
if prefix > slice.NumOut() {
10381039
typecheck.Panicf(1, "prefixed: prefix %d is greater than number of columns %d", prefix, slice.NumOut())
10391040
}
1040-
return &prefixSlice{slice, prefix}
1041+
var pragma Pragma = Pragmas{}
1042+
if slicePragma, ok := slice.(Pragma); ok {
1043+
pragma = slicePragma
1044+
}
1045+
return &prefixSlice{pragma, slice, prefix}
10411046
}
10421047

10431048
func (p *prefixSlice) Prefix() int { return p.prefix }

slice_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,23 @@ func TestHead(t *testing.T) {
810810
assertEqual(t, slice, false, []int{1, 2, 7, 8})
811811
}
812812

813+
// TestPrefixedPragma verifies that Prefixed slices properly adopt pragmas from
814+
// their underlying slices.
815+
func TestPrefixedPragma(t *testing.T) {
816+
slice := bigslice.Const(2, []int{0, 1, 2}, []string{"a", "b", "c"})
817+
slice = bigslice.Map(slice, func(i int, s string) (int, string) {
818+
return i, s
819+
}, bigslice.Exclusive)
820+
slice = bigslice.Prefixed(slice, 2)
821+
pragma, ok := slice.(bigslice.Pragma)
822+
if !ok {
823+
t.Fatal("Prefixed does not implement Pragma")
824+
}
825+
if !pragma.Exclusive() {
826+
t.Error("Prefixed not Exclusive")
827+
}
828+
}
829+
813830
func TestScan(t *testing.T) {
814831
const (
815832
N = 10000

0 commit comments

Comments
 (0)