Comments (3)
but surely it'd be clearer to just write it as normal composition rather than [map]?
Yes if you're composing two functions in application code. However, defining an Traversable
instance for Compose f g
requires Functor instances for both f
and g
. The Traversable
instance is defined in terms of those Functor
instances.
Perhaps it would be less confusing if an implementation of Traversable (Compose f g)
were provided in the Traversable
example.
from fantasy-land.
Function
s in JavaScript have a type Function (a | null | undefined) (b | null | undefined)
, but lets say Function a b
for simplicity's sake. While Function a b
doesn't have a Functor
instance, Function SomeType b
does. It can be defined as follows:
Function.prototype['fantasy-land/map'] = function (f) {
var g = this;
return function (a) {
return f(g(a));
};
};
// usage
// `Function Number Number` composed with `Function Object String` => `Function Number String` or `(Number -> String)`
(x => x + 1)['fantasy-land/map'](x => x.toString())(42); // '43'
As evidenced by the result, you can see that Function.prototype['fantasy-land/map']
is equivalent to Function.prototype['fantasy-land/compose']
.
from fantasy-land.
Ah... makes sense I guess, but surely it'd be clearer to just write it as normal composition rather than [map]
?
from fantasy-land.
Related Issues (20)
- [Question] Type signature for ap HOT 2
- Adding Folktale to implementations.md
- Equivalent for Serial typeclass? HOT 1
- Is really necessary specify "No parts of <...> value should be checked"? HOT 11
- Add Traversable1 HOT 3
- Help understanding use of identity in Traversable laws HOT 2
- Fantasy Land specification version number HOT 1
- Switch to Symbols HOT 2
- Wrong argument in Traversable HOT 4
- Is monet.js compatible? HOT 1
- Why FL specifies the ChainRec typeclass when there is the trampoline monad? HOT 7
- What does "and" mean? HOT 2
- Can someone explain me how I should understand Semigroup? HOT 5
- Remove all OOP features HOT 21
- Traversable and Foldable use multiple variables as arguments HOT 12
- Profunctor should require Contravariant HOT 10
- should Chain properties depends on fantasy-land/ap (and possibly .map)? HOT 4
- Why putting "fantasy-land/" before everything in readme? HOT 3
- Is `Pair` a valid instance of `MonadRec`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fantasy-land.