3 ms·
> And once you start thinking interms of functions, you just won't touch any of those terrible OO programming paradigms Also worth noting (because Elixir was s
by bmelton 7y ago
> And once you start thinking interms of functions, you just won't touch any of those terrible OO programming paradigms
Also worth noting (because Elixir was strange and new for everyone at some point) that a lot of what used to be mind-boggling to me in earlier versions of Elixir/Phoenix have become relatively commonplace when dealing with things like React or modern Javascript.
If you've ever handled a JS promise for something as simple as a `fetch()` query and processed results, you _already understand_ how to build code in functional components.
There's much less difference between
fetch(url)
.then(results => doSomething())
.then(results => doSomethingElse())
and
doSomething()
|> doSomethingElse()
than it looks like at first blush.
- toastal 7y agoUnlike a Promise, I hope you can cancel processes in Elixir
- jhgg 7y agoYou can kill them. Just like processes on your computer!
- capableweb 7y agoYou can cancel a Promise by using AbortController and its AbortSignal, still experimental but supported in most browsers already.
- toastal 7y agoI'll stick to Futures for; Futures work everywhere now and aren't immediately invoked when called with new.
- capableweb 7y agoNot sure exactly what futures you're referring to as there are no "native" futures in any browser (that I know of) so they are either implemented on top of Promises or by using callbacks, and still doesn't solve the problem of cancellation...
- toastal 7y agoYou're right. There's not a native solution. I've used Fluture (https://github.com/fluture-js/Fluture https://github.com/fluture-js/Fluture) for while now as it follows the Fantasy Land spec. The canceler is returned in the Future's constructor. The biggest feature difference in comparison to Promises is that you can pass around a Future adding to the data transformation without it being invoked until fork is called. It's good to know that there exists a way to do this natively now though.