const someFn = ({
doStuffForActiveItems = id,
config = {},
list = [],
delimiter = ''
} = {}) =>
list
.filter(({ isActive = false }) => isActive)
.map((item = {}) =>
doStuffForActiveItems({...config, ...item})
)
.map(({ name = ''}) => name)
.join(delimiter)
const someFn = ({
doStuffForActiveItems,
config,
list,
delimiter,
}) => {
if (Array.isArray(list)) {
const names = list
.filter(({ isActive }) => isActive)
.map((item) => {
const item = item || {}
if (
_.isPlainObject(config) &&
_.isPlainObject(item) &&
typeof doStuffForActiveItems === 'function'
) {
return doStuffForActiveItems({...config, ...item})
}
})
.map(({ name }) => {
name = name || ''
return name
})
if (typeof delimeter !== 'string') {
delimeter = ''
}
return name.join(delimiter)
} else {
return ''
}
}
const gimme1stThingName = (things = [{ name: 'thing name' }]) => {
const [first = { name: 'first thing name ' }] = things
return first.name
}
const gimme1stThingName = (things = [{ name: 'Boaty McBoatface' }]) => {
const [first = { name: 'Boaty McBoatface' }] = things
return first.name
}
const gimme1stThingName = (things = missingArg(`Y U No giv things?`)) => {
const [first = missingArg(`Y things empty?`)] = things
return first.name
}
const missingArg = (message) => { throw new Error(message) }
An algebraic structure with a single associative binary operation and an identity element
An algebraic structure with a single associative binary operation and an identity element
An algebraic structure with a single associative binary operation and an identity element
An algebraic structure with a single associative binary operation and an identity element
+
-
*
/
N + i
i + N
=
N
=
i = 0
N * i
i * N
=
N
=
i = 1
Object to hold fragment
Type: Number
Operator: addition (+)
Identity Element: 0
Type: Number
Operator: multiplication (*)
Identity Element: 1
+
`${x}${y}`
''.concat
S + i = i + S = S
i = ''
`${S}${i}` = `${i}${S}` = S
S.concat(i) = i.concat(S) = S
Type: String
Operator: concat (+, `${}${}`, ''.concat)
Identity Element: ''
&&
||
B && i = i && B = B
i = true
B || i = i || B = B
i = false
Type: Boolean
Operator: &&
Identity Element: true
Type: Boolean
Operator: ||
Identity Element: false
[].concat
[...]
A.concat(i) = i.concat(A) = A
i = []
[...A, ...i] = [...i, ...A] = A
Type: Array
Operator: concat, [...]
Identity Element:[]
Object.assign
{...}
Object.assign(O, i) = Object.assign(i, O) = O
i = {}
{...O, ...i} = {...i, ...O} = O
Type: Object
Operator: merge (Object.assign, {...})
Identity Element: {}
π€
F π€ i = i π€ F = F
i = π€·ββοΈ
const compose = (...fns) => (data) => fns.reduceRight((result, fn) => fn(result), data)
compose
compose(F, i) = compose(i, F) = F
i = π€·ββοΈ
i = (x) => x
Type: Function
Operator: compose
Identity Element: (x) => x
const someFn = ({
doStuffForActiveItems = id, /* <- monoidal identity element */
config = {}, /* <- monoidal identity element */
list = [], /* <- monoidal identity element */
delimiter = '' /* <- monoidal identity element */
} = {} /* <- monoidal identity element */) =>
list
.filter(({ isActive = false }) => isActive)
.map((item = {} /* <- monoidal identity element */) =>
doStuffForActiveItems({...config, ...item})
)
.map(({ name = '' /* <- monoidal identity element */}) => name)
.join(delimiter)