Code Monkey home page Code Monkey logo

Comments (3)

gabejohnson avatar gabejohnson commented on June 12, 2024 1

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.

gabejohnson avatar gabejohnson commented on June 12, 2024

Functions 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.

somebody1234 avatar somebody1234 commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.