We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a functor is associative where
functor.map(g.compose(h)) ≡ functor.map(h).map(g)
Is anyone able to give me an example where a context is not functor?
Wouldn't every functor the does functor.map(g.compose(h)) always be equal to functor.map(h).map(g)?
For example if g is x -> x * 2 h is x -> x + 2
both left and right side give the same result
The text was updated successfully, but these errors were encountered:
I believe if you add something wonky like below as the map function, then it wouldn't be a functor
class functor<...> { ... map(Function<..., ...> mapper) { return mapper.apply(mapper.apply(this.x)); } }
Sorry, something went wrong.
that's true, if it's wonky just check the results!
alternatively as an example, for functors that deal specifically with integers
class Functor<Integer> { ... map(Function<..., ...> mapper) { return mapper.apply(x) + 1; } }
let g = x -> x + 2 and h = x -> x * 2 and functor = new Functor(1) functor.map(h).map(g) = (1 * 2 + 1) + 2 + 1 = 3 + 3 = 6 functor.map(g.compose(h)) = ((1 * 2) + 2) + 1 = 4 + 1 = 5
g = x -> x + 2
h = x -> x * 2
functor = new Functor(1)
functor.map(h).map(g)
(1 * 2 + 1) + 2 + 1
3 + 3
6
functor.map(g.compose(h))
((1 * 2) + 2) + 1
4 + 1
5
I see! Thanks so much for all the replies, I understand now
No branches or pull requests
a functor is associative where
functor.map(g.compose(h)) ≡ functor.map(h).map(g)
Is anyone able to give me an example where a context is not functor?
Wouldn't every functor the does functor.map(g.compose(h)) always be equal to functor.map(h).map(g)?
For example if g is x -> x * 2
h is x -> x + 2
both left and right side give the same result
The text was updated successfully, but these errors were encountered: