barbiturat
6/7/2017 - 2:11 PM

Maybe

Maybe

const STATUS_LIST = ['active', 'draft'];
const payload = {
  state: true,
  status: 'active',
  newDataLength: 2,
  canDelete: true,
};


const getMaybe = (pload, list) => 
  list.includes(pload.status) ? Maybe.Just(pload) : Maybe.Nothing()
 
getMaybe(payload, STATUS_LIST)
  .map(pipe(
    chain(assoc('state'), propSatisfies(val => val >= 1, 'newDataLength')),
    ({ state, canDelete }) => state && canDelete
  ))
  .getOrElse(false);