Closed rjmk closed 7 years ago
Maybe export both APIs?
export function concat<A>(semigroup: Semigroup<A>): (fx: Maybe<A>, fy: Maybe<A>) => Maybe<A> {
return function concat(fx, fy) {
const x = prj(fx)
const y = prj(fy)
if (x == null) {
return fy
}
if (y == null) {
return fx
}
return of(semigroup.concat(x, y))
}
}
export function getSemigroup<A>(semigroup: Semigroup<A>): Semigroup<Maybe<A>> {
return {
concat: concat(semigroup)
}
}
export function getMonoid<A>(semigroup: Semigroup<A>): Monoid<Maybe<A>> {
return {
empty,
concat: concat(semigroup)
}
}
That's really nice (I love the typechecking you get from getSemigroup
)
Are there other APIs which we should export in your opinion? For example concat
in Either
I think it makes sense to aim for parity with the Haskell & Purescript preludes
Sorry for the terseness yesterday! I'll make some PRs (if they'd be well received) for some further instances in the coming days.
Also, how about chainRec? The stack safety can't be typechecked AFAIK, but the signature at least could be
Sure, in the meanwhile I pushed https://github.com/gcanti/flow-static-land/pull/34
:fire:
What do you think about multiple instances of semigroup
for Either? There's the one with no constraints as well:
instance Semigroup (Either a b) where
Left _ <> b = b
a <> _ = a
Ah yes, we are free to implement several instances of Semigroup
, it's the beauty of static-land. We have to just find suitable names :)
Tracking chainRec
here https://github.com/gcanti/flow-static-land/issues/35
@rjmk FYI released in https://github.com/gcanti/flow-static-land/releases/tag/0.2.2
Related to #24.
As well as the
getSemigroup
method, one can alsoAnd type check with
(<A>(a: Semigroup<A>) => ({ concat: concat(a) }: Semigroup(<Maybe<A>>))
I slightly prefer this API, but was wondering if you had strong feelings about it / reasons to avoid it