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

Implement Align type-class #535

Closed
tonymorris opened this issue Sep 18, 2013 · 7 comments
Closed

Implement Align type-class #535

tonymorris opened this issue Sep 18, 2013 · 7 comments

Comments

@tonymorris
Copy link
Member

@tonymorris tonymorris commented Sep 18, 2013

trait Align[F[_]] extends Functor[F] {
  def alignWith[A, B, C]: (These[A, B] => C) => F[A] => F[B]
}

Addresses commonly brought up requests:

Subsumes the Scala standard library (ZipAll).

@xuwei-k
Copy link
Member

@xuwei-k xuwei-k commented Sep 18, 2013

I came up we can implement Traverse#align, but it does not work if stream is infinite. what do you think?

xuwei-k/scalaz@scalaz:2f0e2ff...xuwei-k:5eee5dd

@tonymorris
Copy link
Member Author

@tonymorris tonymorris commented Sep 18, 2013

Yeah I am not big into calling length.

@xuwei-k
Copy link
Member

@xuwei-k xuwei-k commented Sep 18, 2013

There is Align and Unalign implementation in Haskell
http://hackage.haskell.org/packages/archive/these/0.3/doc/html/Data-Align.html

@tonymorris
Copy link
Member Author

@tonymorris tonymorris commented Sep 18, 2013

Yep, We can do a bit better than that too I think :)

@xuwei-k
Copy link
Member

@xuwei-k xuwei-k commented Sep 18, 2013

def unalign[A, B, C]: (These[A, B] => C) => F[A] => F[B] is correct? What is the type C? .

I think unalign should be def unalign[A, B]: F[These[A, B]] => (F[A], F[B]) if generalize unalignStream and unalignList

@tonymorris
Copy link
Member Author

@tonymorris tonymorris commented Sep 18, 2013

Yeah I misnamed it. I mean this:

def alignWith[A, B, C](f: A \&/ B => C): (F[A], F[B]) => F[C]
@xuwei-k
Copy link
Member

@xuwei-k xuwei-k commented Sep 18, 2013

def alignWith[A, B, C](f: A \&/ B => C): (F[A], F[B]) => F[C]

I got it :)

tonymorris added a commit that referenced this issue Sep 18, 2013
tonymorris added a commit that referenced this issue Sep 20, 2013
Align type-class, syntax and instances. Some ideas taken from http://hackage.haskell.org/package/these/

The Align type-class is provides a zip-like operation (align) that maintains list elements that do not align.
@larsrh larsrh closed this Sep 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants