Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Last active February 4, 2016 14:32
Show Gist options
  • Save hodzanassredin/d230313d762d508caee1 to your computer and use it in GitHub Desktop.
Save hodzanassredin/d230313d762d508caee1 to your computer and use it in GitHub Desktop.
reader option functor
let howIsMyName t f = f >> Option.map t
//mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
type Reader<'environment,'a> = 'environment -> 'a
//func application
let run environment (action : Reader<_,_>) = action environment
//functor
let map f (action : Reader<_,_>) : Reader<_,_> = action >> f
type OptionReader<'environment,'a> = Reader<'environment,'a option>
//('a -> 'b) -> ('environment -> 'a option) ('environment -> 'b option)
let mapOptionReader f (action : OptionReader<_,_>) : OptionReader<_,_> = action >> Option.map f
let composeFmaps = (>>)
//('a -> 'b) -> ('environment -> 'a option) ('environment -> 'b option)
let mapOptionReaderC f = composeFmaps Option.map map f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment