Skip to content

Are contraints on function parameters possible? And how do I call the interfaces/functions of type classes? #1629

Answered by xuanduc987
philschonholzer asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible but you will have to pass typeclass instance around.

import { Monoid } from 'fp-ts/Monoid'
import { string } from 'fp-ts'

const merge = <A>(M: Monoid<A>) => (m1: A, m2: A): A => {
  return M.concat(m1, m2)
}

console.log(merge(string.Monoid)("abc", "xyz")) // => abcxyz

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@philschonholzer
Comment options

Answer selected by philschonholzer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants