barbiturat
7/27/2017 - 3:29 PM

modifying an object's field, basing on values of it's other fields.

modifying an object's field, basing on values of it's other fields.

const payload = {state: false, dataLength: 2};

// Assigning "true" to the "state" field if "dataLength" > 1

chain(assoc('state'), propSatisfies(lt(1), 'dataLength'))(payload)
//=> {"dataLength": 2, "state": true}

converge(assoc('state'), [propSatisfies(lt(1), 'dataLength'), identity])(payload)
//=> {"dataLength": 2, "state": true}

ap(flip(assoc('state')), propSatisfies(lt(1), 'dataLength'))(payload)
//=> {"dataLength": 2, "state": true}

lift(assoc('state'))(propSatisfies(lt(1), 'dataLength'), identity)(payload);
//=> {"dataLength": 2, "state": true}