GithubHelp home page GithubHelp logo

memo's Introduction

Memo

This is a Swift microframework providing Memo<T>, with implementations of ==/!= where T: Equatable.

Memo is a convenient way to ensure that an expression producing a value is evaluated precisely once. It can be used to lazily load expensive resources or to delay and memoize recursive evaluation to avoid infinite loops.

Use

Constructing a Memo is easy. Most of the time you just want to lazily memoize an expression, so you’ll want to use the default, unlabelled initializer:

var memos = 0
let closure = Memo { ++memos }

Sometimes you’ll want to pass in a function () -> T. In those cases, use the unevaluated initializer:

let preIncrementMemos = { ++memos }
let lazilyEvaluated = Memo(unevaluated: preIncrementMemos)

Sometimes you’ve already evaluated, or you want to force the evaluation to happen with the construction of the Memo for performance reasons. The evaluated initializer handles this:

let eagerlyEvaluated = Memo(evaluated: ++memos)

Extract the evaluated value via the value property:

let value = implicitClosure.value

Implementation details

Memo is memoized even if you copy it around before it’s evaluated. It uses immutable value type semantics, but does not leak implementation details (i.e. you do not have to hold it in a var to retrieve its value). It does this by means of a private, unobservably-mutable reference type which wraps the inner data.

Documentation

API documentation is in the source.

Integration

  1. Add this repository as a submodule and check out its dependencies, and/or add it to your Cartfile if you’re using carthage to manage your dependencies.
  2. Drag Memo.xcodeproj into your project or workspace, and do the same with its dependencies (i.e. the other .xcodeproj files included in Memo.xcworkspace). NB: Memo.xcworkspace is for standalone development of Memo, while Memo.xcodeproj is for targets using Memo as a dependency.
  3. Link your target against Memo.framework and each of the dependency frameworks.
  4. Application targets should ensure that the framework gets copied into their application bundle. (Framework targets should instead require the application linking them to include Memo and its dependencies.)

memo's People

Contributors

norio-nomura avatar robrix avatar

Watchers

 avatar  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.