I am new to functional programming and I found the following fluture functional programming example that seems to give a really good example for handling database queries and subsequent data manipulation. The caveat however is that in reading about functional programming concepts, Just/Nothing monads seemed to be the suggested approach for handling null checking. 1) How would that fit into this example and 2) if the findOne rejected, would it stop the subsequent chains from running and immediately go to the fork?
import Future from 'fluture';
const processAll = Future.fork(_sendError, _sendResponse);
const _fetchFromDB =
encaseP(userId => myModel.findOne({ id: userId }).exec())
//Future.fromPromise(userId => myModel.findOne({ id: userId }).exec())
processAll(_fetchFromDB(userId)
.chain(getDataGeneric)
.chain(_findDevice)
.chain(_processRequest))
I got this example from the following stackoverflow link and modified the fromPromise to encaseP:
How to make Either Monads be aware of of Async functions(Promises/Future)
I assume that encaseP would replace fromPromise in their example in converting a Promise to a Future.