lens-process: Optics for system processes

[ bsd3, library, system ] [ Propose Tags ]

'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]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.4.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 (info)
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>
Revised Revision 1 made by topos at 2019-06-23T00:49:09Z
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-22T20:39:57Z
Distributions
Downloads 4991 total (31 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-06-22 [all 1 reports]

Readme for lens-process-0.0.4.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.