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
2 answers

Serialize a Zipper?

repl> (-> root zip/down zip/right) [{:answer-keys [5 6], :id 3} {:l [{:id 2, :answer-keys []}], :pnodes [{:answer-keys [2 3 4], :id 1}], :ppath nil, :r ({:answer-keys [7], :id 4})}] I see this data when I print out the zipper on the repl. I am…
Stephen Cagle
  • 14,124
  • 16
  • 55
  • 86
2
votes
1 answer

Easy tree traversal and fast random node access

Edited after Alex Taggart's remark below. I am using a zipper to easily traverse and edit a tree which can grow to many thousands of nodes. Each node is incomplete when it is first created. Data is going to be added/removed all the time in random…
kliron
  • 4,383
  • 4
  • 31
  • 47
2
votes
1 answer

make-node in zipper library

I am trying to create a zipper from a map of my own. According to zipper definition, Usage: (zipper branch? children make-node root) the parameters branch? and children are clear and i am able to define it. But the make-node function is confusing.…
Udayakumar Rayala
  • 2,264
  • 1
  • 20
  • 17
2
votes
3 answers

How to obtain paths to all the child nodes in a tree that only have leaves using clojure zippers?

Say I have a tree like this. I would like to obtain the paths to child nodes that only contain leaves and not non-leaf child nodes. So for this tree root ├──leaf123 ├──level_a_node1 │ ├──leaf456 ├──level_a_node2 │ ├──level_b_node1 │ │ …
marathon
  • 7,881
  • 17
  • 74
  • 137
2
votes
2 answers

How to move zipper to left/right node in clojure?

I'm writing a tree ( business process decision tree ) in clojure data structure . (require clojure.zip :as z) (z/vector-zip [ :billed? [:yes [:check-bank-account] [:check-cash] ] …
Shawn Zhang
  • 1,680
  • 1
  • 12
  • 21
2
votes
2 answers

How to delete laravel delete file after extract?

I am using Zipper to extract uploaded zip file and delete the file after extract. So I upload and extract like this: $f = $request['file']->move(public_path($directory), $fullFileName); \Zipper::make($f)->extractTo(public_path($directory) .…
Alireza Saremi
  • 401
  • 1
  • 7
  • 13
2
votes
1 answer

laravel Error: Your PHP version is not compiled with zip support

i am using zipper to create zip file in laravel 5.3, getting the error as , Error: Your PHP version is not compiled with zip support PHP version : 5.6 chmod($withdrawalFilePath, 0777); $files = glob($withdrawalFilePath .…
Vivek Chaudhari
  • 1,930
  • 1
  • 14
  • 20
2
votes
1 answer

Laravel Chumper Zipper how to extract without specific folder name

I have a zip file with this format: test.zip |- test/ |- test.txt |- test2.txt I'm able to extract using this: $zipper = new Zipper(); $zipper->make('test.zip')->folder('test')->extractTo('foo'); //extracts contents of test…
raz
  • 409
  • 6
  • 17
2
votes
3 answers

Can't Zip RDDs with unequal number of partitions. What can I use as an alternative to zip?

I have three RDDs of the same size rdd1contains a String identifier, rdd2 contains a vector and rdd3contains an integer value. Essentially I want to zip those three together to get an RDD of RDD[String,Vector,Int] but I continuously get can't zip…
Mnemosyne
  • 1,162
  • 4
  • 13
  • 45
2
votes
2 answers

How to move an element within a structure, possibly with zippers?

I have this structure: [{"a" {"b" 1 "c" 2} "children" [{"a" {"b" 3 "c" 4} "children" []}]} {"a" {"b" 5 "c" 6} "children" []} {"a" {"b" 7 "c" 8} "children" [{"a" {"b" 9 "c" 10} "children" []} {"a" {"b" 10 "c" 10} "children" []}]}] I'm…
Chiron
  • 20,081
  • 17
  • 81
  • 133
2
votes
3 answers

Clojure flat sequence into tree

I have the following vector, [-1 1 2 -1 3 0 -1 2 -1 4 0 3 0 0] which represents the tree [[1 2 [3] [2 [4] 3]]] where -1 begins a new branch and 0 ends it. How can I convert the original vector into a usable tree-like clojure structure (nested…
calopter
  • 67
  • 2
2
votes
2 answers

Calculating the depth of a tree data structure - clojure

I'm trying to implement an algorithm to find the depth of a sequence expression through Clojure Zippers. (zip/seq-zip (+ 1 (* 2 3))) This is the way I'm interpreting a sequence to be converted into a tree data structure. Is there a direct method to…
Coding active
  • 1,620
  • 3
  • 23
  • 40
2
votes
2 answers

Clojure Zipper to EDN

I have created the following graph using Clojure Zipper A / | \ B C D / \ E F using the following code: (require '[clojure.zip :as z]) (def g (z/vector-zip ["A" ["B" "C" "D"["E" "F"]]])) Now I want to create a…
palash
  • 137
  • 1
  • 9
2
votes
1 answer

How to create Clojure Zipper

How could I create the following graph using Clojure Zipper (vector-zip): A / | \ B C D / \ E F I have tried (vector-zip ["A" ["B" "C" "D"["E" "F"]] ]) It returns [["A" ["B" "C" "D" ["E" "F"]]] nil] Is it right?
palash
  • 137
  • 1
  • 9
2
votes
3 answers

Recreate a flattened tree

I have a vector of maps, that I'd like to transform in a nested fashion. The data is structured as follows: (def data [{:id 1 :name "a" :parent 0} {:id 2 :name "b" :parent 0} {:id 3 :name "c" :parent 0} {:id 4 :name "a_1" :parent 1} …
boutros
  • 23
  • 3
1 2 3
8 9