Code Monkey home page Code Monkey logo

Comments (3)

satorg avatar satorg commented on June 12, 2024 1

I've just realized there's even a broader issue with Tuple1: depending on imports used, the map method for Tuple1 can change its semantic dramatically. Check this out:

import cats.syntax.functor._

scala> val t1 = Tuple1(List("A", "B"))
val t1: (List[String],) = (List(A, B),)

scala> t1.map(s => s"$s!")
val res0: (String,) = (List(A, B)!,)

However, if I use another syntax import:

scala> import cats.syntax.apply._

scala> val t1 = Tuple1(List("A", "B"))
val t1: (List[String],) = (List(A, B),)

scala> t1.map(s => s"$s!")
val res0: List[String] = List(A!, B!)

I.e. the same t1.map(s => s"$s!") call for exactly the same Tuple1(List("A", "B")) value works differently and produces results of different types depending on whether import cats.syntax.functor._ or import cats.syntax.apply._ is used.

I think it is somewhat confusing.

from cats.

satorg avatar satorg commented on June 12, 2024

Although I don't know for sure the reasoning behind such naming conventions, my guess is that despite Tuple1SemigroupalOps name its methods do not require the Semigroupal typeclass actually – but only Functor, Traverse, etc. Whereas all the other TupleNSemigrioupalOps methods for N >= 2 do require the Semigroupal typeclass.

In other words, we can assume that Tuple1[N] is isomorphic to Id[N] and therefore do not need mapN semantic.

from cats.

m50d avatar m50d commented on June 12, 2024

mapN on a Tuple1 in isolation is kind of silly - but so is any use of Tuple1 in isolation - as you say, Tuple1[N] is isomorphic to Id[N]. The only real reason for having Tuple1 (and therefore Tuple1SemigroupalOps) at all is to operate consistently on tuples of all sizes - if you have to special-case Tuple1 anyway then you might as well just operate on the value inside.

from cats.

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.