lens-process: Optics for system processes

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

'lens-process' is a set of multi-purpose optics and convenience combinators for working with the process library, including a more well-typed api for the parts that can be typed.


[Skip to Readme]

Properties

Versions 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.4.0, 0.0.5.0, 0.0.5.0, 0.1.0.0, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.4.0.0
Change log CHANGELOG.md
Dependencies base (>=4.0 && <5), exitcode (>=0.1.0.2 && <0.1.1), filepath (>=1.0 && <1.5), lens (>=4.0 && <4.18), mtl (>=2.2 && <2.3), process (>=1.5 && <1.7), stm (>=2.5 && <2.6) [details]
License BSD-3-Clause
Copyright (c) 2019 Emily Pillmore
Author Emily Pillmore
Maintainer Emily Pillmore <emilypi@cohomolo.gy>
Category System
Home page https://github.com/emilypi/lens-process
Bug tracker https://github.com/emilypi/lens-process/issues
Source repo head: git clone https://github.com/emilypi/lens-process.git
Uploaded by topos at 2019-06-23T01:20:22Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for lens-process-0.0.5.0

[back to package description]

lens-process

Hackage Build Status

This package is still in Beta!

This package is intended to be on the lighter side, with few dependencies aside from lens. For full disclosure, this is the minimal dependency graph of lens-process:

lens-process dependencies

Motivation

lens-process provides optics for the process package. These optics provide convenient lenses, traversals, and prisms, as well as classy variants for significant classifiable portions of the library for convenience. In addition, we provide some combinators for working with CreateProcess types. The intention of this package is to create a well-typed optical layer for process, reflecting the shape of certain types of commands at the type level. For instance, consider the following:

myStdInProcess
  :: forall a
  . CommandProcess
  -> (Handle -> IO StdStream)
  -> IO (Either Text a)
myStdInProcess cp f g = do
  (mhin, _, _, _) <- createProcess cp
  case mhin of
    Nothing -> error "oh no!"
    Just t -> f t

This is very standard process code. However, if anyone else encounters this code, it is immediately apparent that information is lacking from the type signature. What Handle are we using? What type of command are we running? It is not reflected. Consider instead this replacement:

myStdInProcess
  :: forall a b c
  . (HasStdIn a, IsUseHandle b)
  => a -> (b -> IO c) -> IO c
myStdInProcess cp f = do
  handler <- createProcess cp
  case handler ^? _Stdin . _Just . re _UsesHandle of
    Nothing -> error "oh no!"
    Just t -> f t

What have we gained here? Well, for one, I know I'm working with something that only has a _Stdin, and that i will be piping whatever its _Stdin entry is into a UseHandle. Then, my function handles it accordingly. Much information has been gained! Classy optics gives us the necessary information to proceed as planned with more confidence.