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