• Stars
    star
    49
  • Rank 585,874 (Top 12 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create Clojure maps whose values are only calculated when accessed, either from data or from java objects.

lazy-map https://secure.travis-ci.org/Malabarba/lazy-map-clojure.png?branch=master https://img.shields.io/badge/dryness-68-97CA00.svg https://coveralls.io/repos/Malabarba/lazy-map-clojure/badge.svg?branch=master&service=github

Create maps whose values are only calculated when accessed, either from data or from java objects. Supports both Clojure and Clojurescript!

https://clojars.org/malabarba/lazy-map/latest-version.svg

Documentation

This macro is analogous to lazy-seq. It takes a map (instead of a seq), but the value expressions you write aren’t actually evaluated until they are accessed.

user> (def my-map
        (lazy-map
         {:cause (do (println "Getting Cause")
                     :major-failure)
          :name (do (println "Getting Name")
                    "Some Name")}))
#'user/my-map

user> (:name my-map)
Getting Name
"Some Name"

user> (:name my-map)
"Some Name"

user> (:cause my-map)
Getting Cause
:major-failure

user> (:cause my-map)
:major-failure

You can also assoc new keys into a LazyMap like a regular Clojure map. If you assoc a delay it will act as a lazy value, and if you assoc anything else it acts as a regular value.

user> (def new-map (-> (assoc my-map :surname "Malabarba")
                 (assoc :delayed-surname
                        (delay (println "Resolved")
                               "Late Malabarba"))))
#'user/new-map
user> (:surname my-map)
"Malabarba"
user> (:delayed-surname my-map)
Resolved
"Late Malabarba"

The to-lazy-map protocol

This protocol allows you to convert any java class into a lazy map, where each entry correponds to a method call. Since everything is lazy, you can rest assured the methods won’t actually be called until you use them.

user> (use 'lazy-map.iop)
nil
user> (extend-lazy-map String)
nil

user> (to-lazy-map "My Own Map!")
{:to-char-array #object[clojure.lang.Delay 0x5c3c775a {:status :pending, :val nil}],
 :empty?        #object[clojure.lang.Delay 0x774f63f2 {:status :pending, :val nil}],
 :to-string     #object[clojure.lang.Delay 0x4a62ed8c {:status :pending, :val nil}],
 :intern        #object[clojure.lang.Delay 0x4ddc7018 {:status :pending, :val nil}],
 :chars         #object[clojure.lang.Delay 0x72e5585e {:status :pending, :val nil}],
 :class         #object[clojure.lang.Delay 0x7e39e503 {:status :pending, :val nil}],
 :length        #object[clojure.lang.Delay 0x236a69c5 {:status :pending, :val nil}],
 :trim          #object[clojure.lang.Delay 0xd988100 {:status :pending, :val nil}],
 :bytes         #object[clojure.lang.Delay 0x55671f45 {:status :pending, :val nil}],
 :code-points   #object[clojure.lang.Delay 0x64c7f917 {:status :pending, :val nil}],
 :to-lower-case #object[clojure.lang.Delay 0x1493800b {:status :pending, :val nil}],
 :hash-code     #object[clojure.lang.Delay 0x5d4a8318 {:status :pending, :val nil}],
 :object        #object[clojure.lang.Delay 0x30ba32c3 {:status :pending, :val nil}],
 :to-upper-case #object[clojure.lang.Delay 0x6b6e6a82 {:status :pending, :val nil}]}

user> (:to-upper-case *1)
"MY OWN MAP!"

Note how there’s an entry for each method. Obviously, only methods that takes no arguments (0-arity) are included.

There’s also an extra :object entry holding the string itself.

License

Copyright © 2015 Artur Malabarba

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

smart-mode-line

A powerful and beautiful mode-line for Emacs.
Emacs Lisp
895
star
2

aggressive-indent-mode

Emacs minor mode that keeps your code always indented. More reliable than electric-indent-mode.
Emacs Lisp
850
star
3

beacon

A light that follows your cursor around so you don't lose it!
Emacs Lisp
657
star
4

paradox

Project for modernizing Emacs' Package Menu. With package ratings, usage statistics, customizability, and more.
Emacs Lisp
561
star
5

elisp-bug-hunter

Hunt down errors in elisp files.
Emacs Lisp
271
star
6

emacs-google-this

A set of emacs functions and bindings to google under point.
Emacs Lisp
264
star
7

names

A Namespace implementation for Emacs-Lisp
Emacs Lisp
249
star
8

Nameless

Less is more. Hide package namespace in your emacs-lisp code
Emacs Lisp
134
star
9

fancy-narrow

Emacs package to immitate narrow-to-region with more eye-candy
Emacs Lisp
129
star
10

rich-minority

Emacs package for hiding and/or highlighting the list of minor-modes in the mode-line.
Emacs Lisp
108
star
11

camcorder.el

Tool for capturing screencasts directly from Emacs.
Emacs Lisp
108
star
12

spinner.el

Emacs mode-line spinner for operations in progress
Emacs Lisp
104
star
13

speed-of-thought-lisp

Write elisp at the speed of thought. Emacs minor mode with abbrevs and keybinds.
Emacs Lisp
73
star
14

latex-extra

A series of usability improvements for Emacs latex-mode.
Emacs Lisp
69
star
15

org-agenda-property

Display org properties in the agenda buffer.
Emacs Lisp
65
star
16

gmail-mode

A major-mode for editing gmail messages using markdown syntax (in emacs).
Emacs Lisp
57
star
17

ham-mode

Html As Markdown. Transparently edit an html file using markdown.
Emacs Lisp
42
star
18

control-pianobar

Pair of scripts that interact with pianobar entirely through notification bubbles and hotkeys. No terminal necessary.
Shell
35
star
19

ox-jekyll-subtree

Extension to ox-jexkyll for better export of subtrees
Emacs Lisp
30
star
20

audio-notes-mode

Emacs mode to play audio notes synced from somewhere else.
Emacs Lisp
26
star
21

speed-of-thought-clojure

Write clojure at the speed of thought.
Emacs Lisp
23
star
22

validate.el

Schema validator for Emacs-lisp
Emacs Lisp
23
star
23

emacs-online-documentation

A project meant to keep an updated online documentation of ALL emacs' built-in functions and variables.
Emacs Lisp
22
star
24

html-to-markdown

HTML to Markdown converter written in emacs-lisp.
Emacs Lisp
17
star
25

alpine-osd-notify

Script to run alpine mail client using a notify-osd notification system.
Shell
17
star
26

conkeror-minor-mode

Mode for editing conkeror javascript files.
Emacs Lisp
17
star
27

emacs-archive-tracker

A script in emacs-lisp to track some statistics about emacs package archives.
Emacs Lisp
14
star
28

comment-or-uncomment-sexp

Emacs-lisp command for inteligently commenting and commenting the sexp under point.
Emacs Lisp
9
star
29

org-bibtex

Simple example of combining a .bib file with org-mode.
8
star
30

emacs-documentation-android

Emacs Documentation android app. Search emacs variables/functions and view their documentations on android.
Java
5
star
31

HugeSQLiteCursor

A version of SQLiteCursor which remains fast even when the cursor is arbitrarily large.
Java
4
star
32

EndlessParentheses

Endless Parentheses blog. See http://endlessparentheses.com
HTML
4
star
33

lisp-assistant

A set of functions, variables, and snippets to assist in developing lisp code.
Emacs Lisp
3
star
34

threads-list-mode

tabulated-list-mode specialized at viewing threads
Emacs Lisp
3
star
35

Keystone

Play Hearthstone with the keyboard.
AutoHotkey
2
star
36

Zumi

Rails WebApp for apartment listings
Ruby
2
star
37

hdh

Ruby gem for rendering plain data into HTML
Ruby
2
star
38

Zumi-front

Frontend for https://github.com/Malabarba/Zumi
Vue
1
star
39

display-keys-emacs

Popup that displays keys pressed for certain commands
Emacs Lisp
1
star
40

greek-unicode-insert

Simple keymap to insert Unicode Greek characters in emacs.
Emacs Lisp
1
star