Skip to content

Implement the ReactiveX Sample operator #98

Open
@schmich

Description

@schmich

RxRuby should implement the ReactiveX Sample operator.

I've found Sample in the Rx.NET library useful in my .NET projects and I find myself needing it in my current Ruby project. You can see the Rx.NET implementation here.

I've hacked up something that seems to have the behavior I'm looking for, but it is very untested and probably has some leaks and incorrect corner cases:

module Rx::Observable
  def sample(sampler)
    sample = sampler.map { |e| [e, true] }
    merged = Rx::Observable.merge(self.map { |e| [e, false] }, sample)
    merged.zip(merged.skip(1)).select { |l, r| r[1] }.map { |l, r| l[0] }
  end
end

I looked into implementing Sample myself natively in the library and contributing a pull request, but after looking at the source for some other operators, I think it would take far too much time for me to contribute a correct implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions