Hello, thanks for all the good work.
I'm having issues with the missing support of fantasy land when using ramda:
Ramda exports map, chain .... functions and rxjs/operators does too which is quite disturbing when reading a code:
import { map as rmap, pipe, prop, toUpper, identity } from 'ramda'
import { map as omap, mergeMap } from 'rxjs/operators'
// emitUsername :: Observable<Array<User>> => Observable<String>
const emitUsername : Observable<Array<User>> => Observable<String> = pipe(
omap(rmap(prop('firstname')),
omap(toUpper),
mergeMap(identity),
)
The exemple above is, i hope, clear enough. We can see how "dirty" it can be to read :/. Since rxjs has it's own map and ramda too, this can lead to a very nasty code base.
It is possible to implement fantasy land specification for the observable ?
One solution would be to implement Fantasy Land specification wich attempt to unify those "operators". Very popular tools such as ramda (and maybe lodash fp ?) are using this specification.
By implementing this solution we could have a much cleaner code base:
import { map, chain, pipe, prop, toUpper, identity } from 'ramda'
// emitUsername :: Observable<Array<User>> => Observable<String>
const emitUsername : Observable<Array<User>> => Observable<String> = pipe(
map(map(prop('firstname')),
map(toUpper),
chain(identity),
)
I know that this emitUsername is not the better implementation, but it does the job of showing the issue.
I don't know how much complicated it is to add the fantasy-land/map, fantasy-land/chain ... to the observable prototype but it would be sooo much fun to use !
In our current project, many confusion comes from those separate operators i would love to see RxJs implementing the most famous one such as Functor, Filterable, Apply ...
Last but not least
Many libraries such as crocks, Fluture .... Are exposing types (like Maybe, Either etc..) wich does also supports fantasy-land specification.
If RxJs does the same, it could be very powerfull and simpler to treat a data:
import { map, prop } from 'ramda'
const getUsername = map(prop('username'))
getUsername(Maybe.Just({ username: 'John Doe'})) // Maybe.Just 'John Doe'
getUsername([{ username: 'John Doe' }]) // Array String
getUsername(Observable.of({ username: 'John Doe'})) // Observable 'John Doe'
If we wan't cleaner API by moving to "functions oriented programation", i think it's an interesting point to consider :).
What do you think ?
You may able to refer previous discussion here: https://github.com/ReactiveX/rxjs/issues/34
it doesn't have clear conclusion, but we don't have any active plan or desire at this moment
@kwonoj Since #34 does not have a clear conclusion i decided to open a new one because i can't add any comments and the previous issue since it's closed and i really hope that it will happened ! Has i say, it could be a clever move and make a step forward to a more unified and functional javascript world :unicorn:
Most helpful comment
@kwonoj Since #34 does not have a clear conclusion i decided to open a new one because i can't add any comments and the previous issue since it's closed and i really hope that it will happened ! Has i say, it could be a clever move and make a step forward to a more unified and functional javascript world :unicorn: