Skip to content

Instantly share code, notes, and snippets.

@forestbelton
Last active December 25, 2015 13:59
Show Gist options
  • Save forestbelton/6987926 to your computer and use it in GitHub Desktop.
Save forestbelton/6987926 to your computer and use it in GitHub Desktop.
everyday zipper type
-module(zipr).
-export([new/1, cur/1, to_list/1, next/1, prev/1, addl/2, addr/2]).
new(X) -> {[], X, []}.
cur({_L, X, _R}) -> X.
to_list({L, X, R}) -> lists:reverse(L) ++ [X] ++ R.
next({L, X, [H|R]}) -> {[X]++L, H, R}.
prev({[H|L], X, R}) -> {L, X, [H]++R}.
addl({L, X, R}, X1) -> {L, X1, [X]++R}.
addr({L, X, R}, X1) -> {[X]++L, X1, R}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment