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

Should we have a relative version of zip? #10

Closed
yotamDvir opened this issue Aug 10, 2018 · 0 comments
Closed

Should we have a relative version of zip? #10

yotamDvir opened this issue Aug 10, 2018 · 0 comments

Comments

@yotamDvir
Copy link
Owner

This is zip as it is now:

elm-pivot/Pivot/Map.elm

Lines 81 to 96 in cee1b98

zip : Pivot a -> Pivot ( Int, a )
zip pvt =
let
n =
lengthL pvt
onC =
(,) n
onL =
List.indexedMap (,)
onR =
List.indexedMap ((+) (n + 1) >> (,))
in
mapCLR_ onC onL onR pvt

It indexes the pivot like a list, without any regard to where the center is.
It may be beneficial to have a relative version.

 zipRelative : Pivot a -> Pivot ( Int, a ) 
 zipRelative pvt = 
     let 
         onC = 
             \x -> (0,x) 
  
         onL = 
             List.indexedMap (\i x -> (-1 - i,x)) 
  
         onR = 
             List.indexedMap (\i x -> (i + 1, x)) 
     in 
mapCLR_ onC onL onR pvt 

For example, a situation where one knows their pivot is going to get jumbled, and would like to retain their current positions afterwards.

In such a case we could also change the name of zip to zipAbsolute, leaving less room for confusion. To increase uniformity, we could further replace goTo by goAbsolute; and goBy by goRelative.

In fact, why is it called zip in the first place? index is better...

yotamDvir added a commit that referenced this issue Aug 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant