Code Monkey home page Code Monkey logo

zipp's Introduction

Extensible zipper.

Slogan

Traverse any datatype you want! Even an Int! No constraints on traversed object!*

* You still need to provide Lenses, Traversals or Directions, though.

Example

    data Tree = Bin { _l, _r :: Tree, _naem :: String } | Nip { _naem :: String }
    
    makeLenses ''Tree
    
    data Dir = L | R deriving Show
    
    test = do
        let tree = Bin (Bin (Nip "lol") (Nip "kek") "lal") (Bin (Nip "foo") (Nip "bar") "qux") "all"
    
        let left  = fromTraversal L l
        let right = fromTraversal R r
     
        (tree', res) <- with' tree $ do
            go left
            go left
            change (naem .~ "HELLO")
            up
            up
            go right
            go right
            res <- peek naem
            return (res ++ "?")
      
        print res

The tree' should be a tree with "lol" replaced by "HELLO" and the res would be "bar?".

Documentation

You can do stack haddock.

Capabilites

This is an implementation of iterator that can

  1. go down the structure using a Direction (that might fail to deliver the destination).
  2. Go up to the parent node.
  3. Perform change on a node.

You run it with some object and an Action to be performed. After its done with its actions, it reconstructs the object as a whole - also returning an action result.

It runs on top of any monad you like, and so do its handlers! Just make sure you can throwM in it.

It also doesn't put any constrains on traversed object whatsoever.

You can traverse Int if you so choose, just find some Directions or Lenses over it.

Dependencies

It doesn't depend on lens package, I used microlens-platform instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.