title: Wrap an API function in an RxJs Observable
body: <p>I am a newbie to RxJs and I have an API that I am using for geocoding that provides a function like the following:</p>
  
  <pre><code>simpleGeocode(options)
  * where options = { address: {addr: ... }, success: Function, failure: Function}. The success function returns the geocoded LatLon object.
  </code></pre>
  
  <p>I am using this in Angular app with NGRX Effects and so I would like it to have it as an Observable so I can use the standard Effect setup like:</p>
  
  <pre><code>@Effect()
  public calculateLocation: Observable&lt;void&gt; = this.actions
      .ofType(actions.CALCULATE_LOCATION)
      .switchMap((action) =&gt; {
          let location = action.payload;
  
          let options = {
              address: location.address
          };
           // ...
  
          this.geocodeService.simpleGeocode(options)
              .map(latLon =&gt; new actions.CalculateLocationSuccessAction(latLon);
              .catch(error =&gt; new actions.CalculateLocationFailureAction(error);
          },
  </code></pre>
  
  <p>But I am totally clueless as to how I would wrap that library call to make it into an Observable. I have read some information about bindCallback() from <a href="http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-bindCallback" rel="noreferrer">http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-bindCallback</a> but I don't fully understand it. I did understand it requires a callback method to be the last parameter of the function so it doesn't look like it would work for my situation since both the success and failure functions are passed into the function as part of an object.</p>
  
  <p>How would I make an Observable out of this API method that would map the success callback to the Observable's next and the failure to Observable's error?</p>