What is a lens?

Note: you can copy the file 2-lenses.js below over to and play along from home!

A lens in programming, much like a lens in the real world, allows you to focus in on a small part of a larger whole and then do something with or to

View fullwidth.js
'use strict';
let str = "anime is for losers";
let fw =
.call(str, (c) => c === ' '
? ' '
: String.fromCodePoint(c.codePointAt(0) + 0xFEE0))
View ot.hs
{- |
Operational transformation in Haskell using (co)free (co)monads.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
import Data.List (splitAt)
import Control.Monad
View list_essay_code.js
'use strict';
* Our little list implementation
///// The foundation
let nil = (f) => (x) => x;
let cons = (h) => (t) => (f) => (x) => f(h)(t(f)(x));
let foldr = (list) => (f) => (x) => list(f)(x);
View module_boilerplate.js
* ECMAScript module boilerplate
* (c) 2016 Gatlin Johnson <>
* with significant credit to github user @cwmyers
* Follow this template and your module will be compatible with browsers or any
* number of sophisticated ES dependency systems.
View my_prelude.hs
{- * Foundational functions -}
id :: a -> a
id x = x
const :: a -> b -> a
const x y = x
fix :: (a -> a) -> a
fix f = f (fix f)
View orca.hs
This came from looking at the source for the orc package on hackage.
I wanted to know why it works, and to see if I can come up with an
alternative implementation which does cool things, and possibly provide
a mechanism for orchestrating non-linear tube computations.
-- | Pilfered from the orc package on Hackage.
-- The original is specialized to one MonadIO instance.
-- Also this looks suspiciously like a continuation monad.
View frp_free.hs
import Control.Applicative
import Data.Time (UTCTime, getCurrentTime)
import Control.Monad.Trans.Free
import Control.Comonad
import Control.Comonad.Trans.Cofree
import Data.Functor.Identity
type Next = IO
View hackagedocs
#!/usr/bin/env bash
# hdoc
# (c) Gatlin Johnson <>
# Available under the following license:
View tube_coro.hs
{-# LANGUAGE Rank2Types #-}
import Prelude hiding (break, take)
import Tubes
import Data.Functor.Identity
import Control.Monad (forever)
{- |
This just holds a value and hands it over when the tube asks, or replaces it
with whatever a tube yields.