Is the following semigroup instance lawful (does it respect semigroup laws)?
import { Semigroup } from 'fp-ts/Semigroup'
/** Always return the first argument */
const first = <A>(): Semigroup<A> => ({
concat: (first, _second) => first
})
Yes:
first
,second
and the result ofconcat
(which isfirst
) are all of the same typeA
concat
is associative:concat(concat(first, second), third)
evaluates toconcat(first, third)
which then evaluates tofirst
concat(first, concat(second, third))
evaluates toconcat(first, second)
which then evaluates tofirst