Skip to content

JustItem(slice) will send multiple values, despite being a Single #341

@hexaglow

Description

@hexaglow

Describe the bug
When called with a slice, JustItem returns a Single that sends multiple values. However the documentation (and the name) suggests that a Single should send one value. There appears to be no way to send a slice as a single value, which is very counterintuitive!

To Reproduce
The following code demsonstrates the issue: (also on Go playground)

package main

import (
    "fmt"

    "github.com/reactivex/rxgo/v2"
)

func main() {
    data := []int{1, 2, 3}
    observable := rxgo.JustItem(data)

    for x := range observable.Observe() {
	    fmt.Println("Item:", x.V)
    }
}

Produces output:

Item: 1
Item: 2
Item: 3

Expected behavior
Output:

Item: [1 2 3]

Additional context
The problem appears to be caused by the send function (item.go:75) which switches on the type of each item.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions