class Transformers {

  static <F, E> ObservableTransformer<F, E> fromFunction(
      final Function<F, E> function, @Nullable final Scheduler scheduler) {
    return new ObservableTransformer<F, E>() {
      @Override
      public ObservableSource<E> apply(Observable<F> effectStream) {
        return effectStream.flatMap(
            new Function<F, ObservableSource<E>>() {
              @Override
              public ObservableSource<E> apply(@NonNull F f) {
                Observable<E> eventObservable =
                    Observable.fromSupplier(
                        new Supplier<E>() {
                          @Override
                          public E get() throws Throwable {
                            return function.apply(f);
                          }
                        });
                return scheduler == null ? eventObservable : eventObservable.subscribeOn(scheduler);
              }
            });
      }
    };
  }

  private  Transformers();

}