-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
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
implementation #1
Comments
Would usage be something like? const pythagoras =
ap([square]) // [9,16]
.map(sum) // 25
.map(Math.sqrt) // 5
pythagoras([3,4]) //=> 5 |
I don't understand what's going on in your example, @JAForbes. Here's a straightforward example: > Math.abs.map(Math.sqrt)(-64)
8
> Math.sqrt(Math.abs(-64))
8 |
Oh, I see it now. |
I like the simplicity of your example @davidchambers. I think in the readme we'll need lots of simple examples that solve some concrete problems. If anyone has any ideas, please post away. |
@davidchambers my tweet was wrong, thank you! |
If this is goint to be a proposal, I think we would need to also support Function.prototype.map = function(f) {
var g = this;
return function(...args) { return f(g.apply(this, args)); };
}; obj = {
foo: 1,
bar: function(a) {
return this.foo + a
}.map(Math.sqrt)
}
obj.bar(3) // 2 |
@i-am-tom has written an excellent series of blog posts about Fantasy Land.
|
Funnily enough, @gabejohnson is pushing for Variadic arguments would be unlawful (if we're thinking about Given the ten minutes of thought I've applied, this seems like a compromise that could be accepted by both parties. My preference for this is purely because it's going to be difficult to push anything functional on the larger JS audience without bastardising it, which would be a shame. Thoughts? |
I like this approach. It allows us to be less concerned about functions being lawful, without harming chances of having lawful implementations in the distant future when the value of lawfulness has been proven out in the mainstream. |
If this is a proposal for ECMAScript, you might want to speak the language: use Flow or TypeScript-like syntax for describing types instead of Haskell syntax. |
Start with the type of
map
as defined by the Functor type class:Replace
Functor f => f
withFunction x
:Replace
Function $1 $2
with($1 -> $2)
:Rename type variables:
Here's the implementation from sanctuary-type-classes:
We should add something similar to the readme:
It's worth noting that this is different from the implementation in your tweet, @puffnfresh. Unless I'm mistaken your version does not have a type compatible with
fantasy-land/map
.The text was updated successfully, but these errors were encountered: