diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 0ac7e8a189..51df596278 100755 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -920,6 +920,8 @@ PRIVATE> ] [ generic-flip ] if ] unless ; +: reduce1 ( seq quot -- result ) [ unclip ] dip reduce ; inline + :: reduce-r ( list identity quot: ( obj1 obj2 -- obj ) -- result ) list empty? diff --git a/extra/file-trees/file-trees.factor b/extra/file-trees/file-trees.factor index 77952c8425..d92309ca77 100644 --- a/extra/file-trees/file-trees.factor +++ b/extra/file-trees/file-trees.factor @@ -1,6 +1,6 @@ USING: accessors arrays delegate delegate.protocols io.pathnames kernel locals sequences -ui.frp vectors make ; +ui.frp vectors make strings ; IN: file-trees TUPLE: walkable-vector vector father ; @@ -31,8 +31,16 @@ DEFER: (tree-insert) : add-paths ( pathseq -- {{name,path}} ) "" [ [ "/" glue dup ] keep swap 2array , ] [ reduce drop ] f make ; -: create-tree ( file-list -- tree ) [ path-components add-paths ] map - { "/" "/" } [ [ tree-insert ] curry each ] keep ; +: go-to-path ( path tree -- tree' ) over empty? [ nip ] + [ [ unclip ] [ children>> ] bi* swap [ swap node>> = ] curry find nip go-to-path ] if ; + +: find-root ( pathseq -- root ) dup flip + [ [ dupd = [ ] [ drop f ] if ] reduce1 ] find-last drop + [ first ] dip head-slice >string path-components ; + +: create-tree ( file-list -- tree ) [ find-root ] + [ [ path-components add-paths ] map { "/" "/" } [ [ tree-insert ] curry each ] keep ] bi + go-to-path ; : ( tree-model -- table ) [ node>> 1array ] >>quot diff --git a/extra/file-trees/file-trees.factor copy b/extra/file-trees/file-trees.factor copy deleted file mode 100644 index e3324d9834..0000000000 --- a/extra/file-trees/file-trees.factor copy +++ /dev/null @@ -1,34 +0,0 @@ -USING: accessors arrays delegate delegate.protocols -io.pathnames kernel locals namespaces prettyprint sequences -ui.frp vectors ; -IN: file-trees - -! There should be optional extra information you can provide -TUPLE: tree node children ; -CONSULT: sequence-protocol tree children>> ; - -: ( start -- tree ) V{ } clone - [ tree boa dup children>> ] [ ".." swap tree boa ] bi swap push ; - -DEFER: (tree-insert) - -: tree-insert ( path tree -- ) [ unclip ] [ children>> ] bi* (tree-insert) ; -:: (tree-insert) ( path-rest path-head tree-children -- ) - tree-children [ node>> path-head node>> = ] find nip - [ path-rest swap tree-insert ] - [ - path-head tree-children push - path-rest [ path-head tree-insert ] unless-empty - ] if* ; - -: create-tree ( file-list -- tree ) [ path-components ] map - t [ [ tree-insert ] curry each ] keep ; - -: find-path ( tree -- string ) dup node>> tuck t = - [ 2drop f ] [ children>> first find-path "/" glue ] if ; - -: ( tree-model -- table ) - [ node>> 1array ] >>quot - [ selected-value>> ] - [ swap >>model ] bi - [ find-path ] >>val-quot ; \ No newline at end of file