Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More doc.

  • Loading branch information...
commit 4be113923084f25980893786fc594ed671fc8745 1 parent e679cb4
Jesper Louis Andersen authored

Showing 1 changed file with 26 additions and 3 deletions. Show diff stats Hide diff stats

  1. +26 3 src/lens.erl
29 src/lens.erl
@@ -18,6 +18,12 @@
18 18 %% Erlang, even though what I will be able to do at spawn(fun() ->
19 19 %% fest(2012) end) will be limited in extent.
20 20 %%
  21 +%% In the longer run, it can be expanded further so we get a full
  22 +%% lens-library with parse transforms on top as well. But for now, we
  23 +%% mostly go for a simple analysis of the library - written over the
  24 +%% course of roughly 24 hours on and off. The sun is shining and
  25 +%% drinking beer in the sun also has priority in this world :)
  26 +%%
21 27 %% Much credit has to be given to Benjamin C. Pierce for describing
22 28 %% lenses initially and to Sebastiaan Visser and many other members
23 29 %% of the Haskell community for first writing up lenses and
@@ -32,7 +38,19 @@
32 38 %% ----------------------------------------------------------------------
33 39
34 40 %% This is not built for the sake of raw conversion speed. If you need
35   -%% that, you need something else. This is built because it is
  41 +%% that, you need something else. This is built because it is
  42 +%% extremely flexible when you want to do surgery on different
  43 +%% structures in Erlang.
  44 +%%
  45 +%% The coolest part is that you can use a lens library to operate
  46 +%% while transforming one data structure into a another. As an
  47 +%% example, the Harmony project can convert seamlessly between
  48 +%% different bookmark formats of IE, Chrome, Firefox and so on because
  49 +%% it can abstract the structure, alter it the right way, and
  50 +%% concretize the structure for one of the other browsers.
  51 +%%
  52 +%% Getting the same ability in Erlang is the goal of this library.
  53 +
36 54 %% LENS DEFINITIONS
37 55 %% ----------------------------------------------------------------------
38 56
@@ -371,9 +389,9 @@ t2() ->
371 389 %%
372 390
373 391 %% But it turns out there another way. We can cast the kitten by
374   -%% creating an abstract view where the kitten is a list-like
  392 +%% creating an abstract view where the kitten is a flattened list
375 393 %% structure. Then when we cast back the kitten into JSON, we can use
376   -%% that list-like structure to recreate the kitten as JSON.
  394 +%% that list structure to recreate the kitten as JSON.
377 395 abs_lens_kitten_2() ->
378 396 lists:unzip(
379 397 lists:flatten(
@@ -394,6 +412,11 @@ abs_lens_kitten_j_2() ->
394 412 %% JSON object. In a future update of the library this problem can
395 413 %% probably be eliminated by following the exposition of functional
396 414 %% lenses more closely.
  415 +%%
  416 +%% The thing we are missing is "failing" lenses where they return
  417 +%% something of term Omega. If we had this, we could handle the case
  418 +%% by building up the structure from "nothing". But as it currently
  419 +%% stands, we can't.
397 420 json_kitten_init() ->
398 421 [{<<"color">>, []}].
399 422

0 comments on commit 4be1139

Please sign in to comment.
Something went wrong with that request. Please try again.