spotify-fp-example icon indicating copy to clipboard operation
spotify-fp-example copied to clipboard

can't use the Fn monoid(semigroup)

Open ghost opened this issue 8 years ago • 2 comments

I'm trying to use your implementation of Fn monoid to concat some functions but it keeps throwing me an error saying concat is not a function...

const Fn = f =>
({
  fold: f,
  concat: o =>
    Fn(x => f(x).concat(o.fold(x))),
  inspect: () => `Fn(${f})`
})

const fn = Fn(x => x + 1)

console.log(fn.concat(Fn(x => x - 1)).fold(3).inspect()) //TypeError: f(...).concat is not a function

i understand that f(x) does not have the concat method because f is not wrapped inside Fn on this context, but what am getting wrong... is this a bug or i am not using it propperly?

ghost avatar Jan 12 '17 22:01 ghost

You've probably long resolved the issue @mcarvalho but I think the referenced PR will fix the problem you were having.

aabrook avatar Jul 16 '17 06:07 aabrook

Each Fn should return a monoid

DrBoolean avatar Jul 18 '17 17:07 DrBoolean