- Source:
Methods
pick(paths) → {Object}
- Source:
- Signature:
-
[String] -> Object -> Object
- Category:
-
- Object
Example
const pickNameAge = pick (['age', 'name'])
pickNameAge({ age: 19, name: 'John', zip: 2819, color: 'red', sex: 'male' })
// => { age: 19 name: 'John' }
Parameters:
Name | Type | Description |
---|---|---|
paths |
Array.<String> | list of properties you want to pick |
Returns:
Object containing only the specified properties
- Type
- Object
select(defaultVal, options, field, item) → {Any}
- Source:
- Signature:
-
a -> StrMap a -> String -> Object -> a
- Category:
-
- Logic
Creates a function that takes an object and selects one value from a map of options or returns the default value. Please note that it only works on objects, so it is intended to clasify objects or select values based on object's properties
Example
const options = {'Joe':'admin','Daniel':'user'};
const showRole = select ('non-user') (options) ('name')
showRole ({name:'Daniel', age: 18}) // => 'user'
showRole ({name:'NoBody', age: 18}) // => 'non-user'
Parameters:
Name | Type | Description |
---|---|---|
defaultVal |
Any | The default value to return if nothing matches |
options |
Object | An object containing the options to consider |
field |
String | which field determines the classification of the input object |
item |
Object | An object to clasify looking at the provided field and searching for it on the options map |
Returns:
The selected option or the default value
- Type
- Any
takeAction(defaultAction, options, field, item) → {Any}
- Source:
- Signature:
-
(a -> b) -> StrMap (a -> b) -> String -> Object -> b
- Category:
-
- Logic
Creates a function that takes an object and executes one action on it.
The action is selected looking at the value of the property field
and searching for it on the map of actions. If no action matches then the default action is executed on the input object
Please note that it only works on objects, so it is intended to execute actions on objects based on one of the object's properties
Example
const options = { admin: u => ({...u, superPowers: true })
, user: ({...u, superPowers: false })
};
const defaultAction = x => ({...x, banned: true})
const registerUser = takeAction (defaultAction) (options) ('role')
registerUser ({name:'Daniel', age: 18, role: 'admin' }) // => {name:'Daniel', age: 18, role: 'admin', superPowers: true }
registerUser ({name:'NoBody', age: 18, role:'no-role'}) // => {name:'NoBody', age: 18, role:'no-role', banned: true}
Parameters:
Name | Type | Description |
---|---|---|
defaultAction |
function | The default action to execute if nothing matches |
options |
Object | An object containing functions to execute when the property of the object matches |
field |
String | A property on the input object to select wich action to take |
item |
Object | An object to execute an action on, looking at the provided field and searching for it on the actions map |
Returns:
The return value of the selected option executed on the input object
- Type
- Any