Skip to content

Instantly share code, notes, and snippets.

@escherlies
Created February 24, 2023 09:58
Show Gist options
  • Save escherlies/2ec3cdfd517704432edfa753b6627d02 to your computer and use it in GitHub Desktop.
Save escherlies/2ec3cdfd517704432edfa753b6627d02 to your computer and use it in GitHub Desktop.
An Elm context type that can be run everywhere. Like a Reader.
module Context exposing (..)
type Context a b
= WithContext (a -> b)
withContext : (a -> b) -> Context a b
withContext =
WithContext
runContext : Context a b -> a -> b
runContext (WithContext fn) a =
fn a
@escherlies
Copy link
Author

Upon further discussion, this actually is a Reader. 😄

See Punie/elm-reader

With open records as environment, the environments can be composed and scoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment