如何在RxScala / Java中使用指定条件取消映射的Observable?

时间:2016-03-26 06:09:12

标签: rx-java observable rx-scala

原始可观察------ a ------- b ------- c ---------- d -------->。 ...
映射可观察----- A ------- B(完成)
简单的代码如下:

  val original = Observable.just('a', 'b', 'c', 'd')
  val mapped = original.map(x => x.toUpper)
  //how to let `mapped` Observable stop emit event when received 'b' from original?
  //do something
  mapped.subscribe(x => println(x)) //make it only print A ,B

如何在B这个指定条件下完成映射的observable?

更新takeUntil方法
takeUntil似乎是一个标准答案,但我的编辑显示此方法以Observable[Any]为参数。请参阅定义,
def takeUntil(that: Observable[Any]): Observable[T]

如果我使用以下代码

  val original = Observable.just('a', 'b', 'c', 'd').takeUntil(x => x == 'b')

发生编译错误

Error:(74, 64) missing parameter type
  val original = Observable.just('a', 'b', 'c', 'd').takeUntil(x => x == 'b')
                                                           ^

我们使用相同的套餐吗?我的sbt依赖是"com.netflix.rxjava" % "rxjava-scala" % "0.20.7"

1 个答案:

答案 0 :(得分:1)

使用class LocationLocationRelationshipsController < ApplicationController before_action :set_location_location_relationship, only: [:show, :edit, :update, :destroy] # GET /location_location_relationships # GET /location_location_relationships.json def index @location_location_relationships = LocationLocationRelationship.all end # GET /location_location_relationships/1 # GET /location_location_relationships/1.json def show end # GET /location_location_relationships/new def new @location_location_relationship = LocationLocationRelationship.new end # GET /location_location_relationships/1/edit def edit end # POST /location_location_relationships # POST /location_location_relationships.json def create @location_location_relationship = LocationLocationRelationship.new(location_location_relationship_params) respond_to do |format| if @location_location_relationship.save format.html { redirect_to @location_location_relationship, notice: 'Die Distanz wurde angelegt.' } format.json { render :show, status: :created, location: @location_location_relationship } else format.html { render :new } format.json { render json: @location_location_relationship.errors, status: :unprocessable_entity } end end end # PATCH/PUT /location_location_relationships/1 # PATCH/PUT /location_location_relationships/1.json def update respond_to do |format| if @location_location_relationship.update(location_location_relationship_params) format.html { redirect_to @location_location_relationship, notice: 'Die Distanz wurde aktualisiert.' } format.json { render :show, status: :ok, location: @location_location_relationship } else format.html { render :edit } format.json { render json: @location_location_relationship.errors, status: :unprocessable_entity } end end end # DELETE /location_location_relationships/1 # DELETE /location_location_relationships/1.json def destroy @location_location_relationship.destroy respond_to do |format| format.html { redirect_to location_location_relationships_url, notice: 'Die Distanz wurde gelöscht.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_location_location_relationship @location_location_relationship = LocationLocationRelationship.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def location_location_relationship_params params.require(:location_location_relationship).permit(:predecessor_id, :successor_id, :tour, :distance, :sequence, :binary_variable) end end ,它完全符合您的需要。