-
I need a Applicative of Map. instance (Monoid k, Ord k) => Applicative (Map k) where
pure a = singleton mempty a
(<*>) mkab mka =
let f = do
(k1, ab) <- toList mkab
(k2, a) <- toList mka
return (k1 `mappend` k2, ab a)
in fromList f I want to implement the equivalent of this piece of code using fp-ts. I tried to imitate Can anyone help me out doing this? I would appreciate little guide line. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I think I've done it function getApplicativeMap<K, T>(
kMon: Monoid<K>,
kOrd: Ord<K>
): Applicative2C<map.URI, K> {
return {
_E: kMon.empty,
of(x) {
const t = tup(kMon.empty, x);
return pipe([t], fromTuples(kOrd));
},
map(fa, f) {
return map.map(f)(fa);
},
URI: map.URI,
ap(fab, fa) {
return pipe(
fab,
map.toArray(kOrd),
array.chain(([k1, ab]) =>
pipe(
fa,
map.toArray(kOrd),
array.map(([k2, a]) => tup(kMon.concat(k1, k2), ab(a)))
)
),
fromTuples(kOrd)
);
},
};
} |
Beta Was this translation helpful? Give feedback.
I think I've done it