Skip to content
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

FromFoldable and FromFoldable1 #1513

Closed
fommil opened this issue Nov 13, 2017 · 10 comments
Closed

FromFoldable and FromFoldable1 #1513

fommil opened this issue Nov 13, 2017 · 10 comments
Labels
scalaz7 Scalaz 7.x
Milestone

Comments

@fommil
Copy link
Contributor

fommil commented Nov 13, 2017

Maybe I'm not fully grokking Unfoldable (which should probably have a ticket) but I found myself needing these trivial little things

trait FromFoldable[F[_]] {
  def fromFoldable[G[_]: Foldable, A](g: G[A]): F[A]
}
trait FromFoldable1[F[_]] {
  def fromFoldable1[G[_]: Foldable1, A](g: G[A]): F[A]
}

with mostly trivial implementations that all our data types could have and could have a CanBuildFrom implicit for legacy reasons. This allows the removal of a lot of methods across the board that are effectively Foldable.toAHardCodedDataType

I guess what we lose is the ability for Foldable[IList] to have an optimal toIList method, and such, which is maybe an argument to retain some hardcoded methods on Foldable.

Possibly related to #1452 and #1448

@fommil fommil added this to the 7.3.0 milestone Nov 13, 2017
@jbgi
Copy link
Member

jbgi commented Nov 13, 2017

@fommil did you have a look at Reducer (and maybe Generator)? I think they could help.

In particular I think we could add the following to Foldable:

  def reduceTo[A, M](fa: F[A])(implicit M: Reducer[A, M]): M = ???
  def to[A, F[_]](fa: F[A])(implicit M: Reducer[A, F[A]]): F[A] = reduceTo[F[A]]

But maybe there is already a better way that I did not see.

@Jacoby6000
Copy link
Contributor

Jacoby6000 commented Nov 13, 2017

@jbgi interestingly, it looks like ReducerOps has almost those exact methods hidden inside a sealed abstract class, UnfoldTo.

sealed abstract class UnfoldTo[C] {

@fommil
Copy link
Contributor Author

fommil commented Nov 13, 2017

I love deleting hacky code that I wrote 😄 I'll take a look and report back tonight.

We should definitely get these added to Foldable. For 7.3 I'm all in favour of removing the stdlib collection methods on Foldable and requiring people to "reduce" to a LiterallyCantEvenBuildFrom

@fommil
Copy link
Contributor Author

fommil commented Nov 14, 2017

I think I need a Reducer1 (for non empty things)

@jbgi
Copy link
Member

jbgi commented Nov 14, 2017

@fommil yes, could be worth solving #1038 for 7.3

@fommil
Copy link
Contributor Author

fommil commented Nov 26, 2017

@fommil
Copy link
Contributor Author

fommil commented Dec 22, 2017

@jbgi I'm still not getting Reducer... can you please show me an example of using it to create a NonEmptyList from a Foldable?

@jbgi
Copy link
Member

jbgi commented Dec 22, 2017

Yeah, will try to put together a Reducer1 over the holidays

@fommil
Copy link
Contributor Author

fommil commented Dec 22, 2017

@jbgi much appreciated, this is needed by scalaz-deriving (for the N-arity case) and my hacky FromFoldable1 is... hacky.

@fommil fommil added scalaz7 Scalaz 7.x and removed scalaz7 Scalaz 7.x labels Jun 17, 2018
@fommil
Copy link
Contributor Author

fommil commented Jun 17, 2018

I'm going to close this in the hope that reducers will solve the issue of creating a data structure from a list / nel

@fommil fommil closed this as completed Jun 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scalaz7 Scalaz 7.x
Projects
None yet
Development

No branches or pull requests

3 participants