Skip to content

Add GCursor and KLens types for traversing data with history#15

Open
mrdziuban wants to merge 3 commits intomasterfrom
gcursor
Open

Add GCursor and KLens types for traversing data with history#15
mrdziuban wants to merge 3 commits intomasterfrom
gcursor

Conversation

@mrdziuban
Copy link
Contributor

No description provided.

def empty[A]: CursorHistory[A] = new CursorHistory(Vector(), None)
lazy val empty: CursorHistory = CursorHistory(Vector(), None)

implicit def eqCursorHistory[A]: Eq[CursorHistory[A]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was never an A ?

* @tparam NewValue The type of the new value
* @param NewFocus The type of the new focus
*/
final type Next[NewValue, NewFocus] = GCursor.AuxL[T, NewValue, NewFocus, Self]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting to look like profunctor optics

CursorHistory(history, Some(NonEmptyVector.of(failedOp)))

@inline final private def id[B](b: B): Id[B] = b
@inline final private def dup[B](b: B): Id[(B, B)] = (b, b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is 1/2 monoid and 1/2 comonoid - worth thinking about b/c those are precursors to monad/comonad if you don't have either already


lazy val root: GCursor.Top[T] = self.root
lazy val focus: NewFocus = newFocus
lazy val last: Option[GCursor.AuxL[T, A, self.Focus, self.Last]] = Some(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wild

* @param ev Evidence that the current focus is a `(List[A], Int)`
* @see def moveList
*/
final def rightN(n: Int)(implicit ev: Focus =:= (List[A], Int)): Either[CursorHistory, Next[A, (List[A], Int)]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking like a zipper. comonad

* @param ev Evidence that the current focus is a `List[B]`
* @return A new cursor focused on the first element in the list, `None` if the list was empty
*/
final def downArray[B](implicit ev: A =:= List[B]): Either[CursorHistory, Next[B, (List[B], Int)]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

Copy link
Contributor

@beezee beezee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to see you keeping forward motion, this is some rare-air code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants