Giter Site home page Giter Site logo

violattice / cascade Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lilactown/cascade

0.0 0.0 0.0 96 KB

A library of continuation-passing, thunk-producing versions of many Clojure core functions.

License: Eclipse Public License 2.0

Emacs Lisp 0.25% Shell 0.18% Clojure 99.56%

cascade's Introduction

⛰️ cascade

Clojars Project cljdoc badge

Cascade is a library of continuation-passing, thunk producing versions of many Clojure core functions.

The goal is to allow essentially unbounded recursion and mutual recursion of seq operations. This means that the seq operations in this library must not use the call stack. Instead, they use a combination of continuation-passing to ensure that operations can always be in the tail position and trampolining to ensure that operations do not use the call stack.

This provides the ability to write recursive algorithms that work on very nested data structures in Clojure(Script) using familiar operations.

cascade.core

cascade.core aims to cover

  • seq operations: reduce, transduce, into, and common transducer-producing fns
  • CPS fn composition: identity, complement, comp

All seq operations can be passed a continuation as first argument, which will be called on completion of the operation, and returns a thunk (0-arity function) which can be called to begin the operation. A thunk will return either another thunk, which can be called to continue the operation, or the result. Thus, they are meant to be used with clojure.core/trampoline.

If a continuation is not passed in to most seq operations, it is assumed you want to run the operation eagerly and will trampoline for you, returning the result.

Transducers

Transducer-producing functions like map, filter, etc. take functions which accept a continuation and the element of the sequence they are operating on, and should call the continuation with the result instead of returning it.

When passed a single function, they return a transducer for use with cascade.core/transduce and cascade.core/into.

When passed a function and a collection, they will eagerly execute the operation using trampoline and return the result.

When passed a continuation, a function and a collection, they will return a thunk, meaning it can be trampolined.

cascade.hike

What is a hike, but a really long walk?

cascade.hike is like clojure.walk, but defines walk in a way that supports walking very large, nested data structures without using the call stack.

Defines recursive tree operations for Clojure data structures. Functions in this namespace take any data structure (list, vector, map, set, seq) and traverses those forms.

cascade.hike/walk is a generic tree walker that uses continuation-passing and returns thunks. It takes any data structure, calls a function with a continuation on every element, and uses the value passed into the continuation in place of the original. This makes it easier to write recursive search-and-replace functions for very nested data that do not use the call stack, as shown in the rest of the functions in this namespace.

License

Copyright © 2021 Will Acton. Distributed under the EPL 2.0.

cascade's People

Contributors

lilactown avatar

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.