Questions tagged [zipper]

A zipper is a technique of representing a data structure so that it is convenient for traversal and updates, especially in pure functional languages.

A zipper is a technique of representing an aggregate data structure so that it is convenient for writing programs that traverse the structure arbitrarily and update its contents, especially in purely functional programming languages.

The basic idea is that an existing list- or tree-like data structure is augmented with a representation of a "focus" on a single item in the tree in a way that permits efficient lookups and updates at the focus point.

A simple example is a zipper for a list, consisting of a pair of two lists. For example, the position of 3 in the list (1,2,3,4,5) is represented by the pair ((2,1),(3,4,5)). To insert a new item or replace 3 with another item with this representation can be done in constant time since 3 is at the head of the second list of the pair. Traversing the list is similarly easy: remove the head of either list and cons it with the other list.

You can read more about zipper in Haskell in the Haskell Wikibook.

126 questions
3
votes
1 answer

How to compress file on angular 8 production build

We need to improve performance of website, that was built in angular 8 How to compress (gzip/brotli) angular file on production build?
3
votes
0 answers

Laravel Chumper/Zipper Permission Denied while extracting

I just installed Chumper/Zipper to extract zip files which will be uploaded. After upload I want to extract the file. So I tried this way: \Zipper::make(storage_path($path . $zip_file))->extractTo($path); So $path is a folder in my storage folder…
Noel Lie
  • 31
  • 2
3
votes
2 answers

How to get nested nodes using xml-> in clojure.data.zip?

I'm finding the usage of xml-> extremely confusing. I've read the docs and the examples but can't figure out how to get the nested nodes of an xml doc. Assume the following xml is in a zipper (as from xml-zip):
Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91
3
votes
1 answer

How do I perform a zip iterator in reverse? - Chapel

How can I perform a zip iterator in reverse order? I need to shift the elements of a sub array. My code is as follows: for (x,y) in zip({c..d by stride},{a..b by stride},){ A1[x]=A1[y]; } I need to perform this in reverse order(i.e b-->a &…
xSooDx
  • 493
  • 1
  • 5
  • 19
3
votes
2 answers

How do I format a tree so that it works with Clojure's zipper?

I am creating trees of s-expressions for a genetic programming problem, and need to alter parts of the trees during the evolution process. I came across the Clojure zipper function that seems like it should be perfect, but for the life of me I can't…
Craig Glennie
  • 5,913
  • 1
  • 14
  • 6
3
votes
1 answer

Clojure zippers path function not complete?

EDIT #2: This entire question and exploration were based on my missing the fundamental notion of zippers; that they represent a perspective in a datastructure from the point of view of a particular node. So a zipper is - at all times - a pair of the…
Oliver Mooney
  • 155
  • 1
  • 7
3
votes
1 answer

Can someone give an example of how edit function for clojure.zip works?

I am a newbie to clojure and i was working with clojure.zip, and was not able to figure out how to use the edit function in it. If someone can give me a working example of how it works it would be really helpful. say for example i have a binary…
Harsh Shah
  • 368
  • 3
  • 17
3
votes
1 answer

Effects of changing a node in a binary tree

Suppose I want to change the orange node in the following tree. So, the only other change I'll need to make is in the left pointer of the green node. The blue node will remain the same. Am I wrong somewhere? Because according to this article (that…
Lazer
  • 90,700
  • 113
  • 281
  • 364
3
votes
3 answers

Apply function to one element only in list or array in Scala

For any given list or array, for instance val list = (1 to 3).toList val array = (1 to 3).toArray and a given function that maps from and onto the collection type, for instance def f(v: Int): Int = v + 10 how to apply f to the ith element of list…
elm
  • 20,117
  • 14
  • 67
  • 113
3
votes
1 answer

Solving Twitter Puddle with Zipper

This is a follow-up to my previous question. Consider the following puzzle I would like to generate a waterLevel array, so that the i-th item is the water level at the i-th point and then sum them up to solve the puzzle. waterLevel[i] = max(0,…
Michael
  • 41,026
  • 70
  • 193
  • 341
3
votes
3 answers

Zipping unequal length lists in scala

I want something like this: def unequalZip[A, B](a: Iterable[A], b: Iterable[B]) = Iterable[(Option[A], Option[B])] where the items from the shorter iterable is matched with items from longer iterable using Nones
pathikrit
  • 32,469
  • 37
  • 142
  • 221
3
votes
1 answer

Is there a more concise way to remove a top level JSON property using Argonaut?

Let's say I have this little Argonaut Json instance: import argonaut._, Argonaut._ Json.obj( "id" := 42, "viewed" := false ) Now, I want to remove the pair whose key is viewed. I found the following to work, but it's a bit too verbose. Is…
Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
3
votes
1 answer

In Clojure how to apply function on a collection

I am trying to apply function for extracting content of one tag from xml on a collection of tags. Basically, I am trying to make a function that will extract content from xml, like this (defn get-events [xz] (map (juxt #(zf/xml1-> % :title…
Vesna
  • 345
  • 2
  • 11
3
votes
1 answer

Clojure Zipper over a heterogeneous tree

I'm having problems writing a zipper that can traverse a heterogeneous tree of nodes. I have i) a list of maps. Each map has ii) an :inputs key, whose value is a list of maps. I want to use a zipper to visit each of those leaves and add a computed…
Nutritioustim
  • 2,686
  • 4
  • 32
  • 57
3
votes
1 answer

Zipping zippers in Anti-XML

In this question, the asker wants to transform documents like this: The capitals of Bolivia are and . Into this: The capitals of Bolivia are and . As I…
Travis Brown
  • 138,631
  • 12
  • 375
  • 680
1 2 3
8 9