Skip to content

Instantly share code, notes, and snippets.

@Ezku
Last active August 29, 2015 14:04
Show Gist options
  • Save Ezku/6e01a03f2e36c5edbf46 to your computer and use it in GitHub Desktop.
Save Ezku/6e01a03f2e36c5edbf46 to your computer and use it in GitHub Desktop.
# See: https://github.com/fantasyland/fantasy-land#comonad
# data Store b a = Store b (b -> a)
# instance Comonad (Store b)
class Store
# { value: b, set: (b -> a) } -> Store b a
constructor: ({@value, @set}) ->
# () -> b
from: -> @value
# () -> a
extract: -> @set @value
# (a -> c) -> Store b c
map: (f) -> new Store @value, (b) -> f @set b
# (Store b a -> b) -> Store b a
extend: (f) -> new Store (f this), @inject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment