hydraulics: Lift any pure function over any Applicative stack.
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.
This package contains a family of functions based on familiar Applicative
,
Functor
, Traversable
, and Foldable
methods but with the ability
to operate on stacks of arbitrary depth.
For example, liftAll
is like the liftA2
and liftA3
functions except that it can lift a
function through multiple layers of Applicative
s instead of just one. Additionally,
it can lift a function of arbitrary arity, not just a 2 argument function like with liftA2
.
The term "stack" is used in this library's documentation to refer to something like
Maybe [Either Bool [Int]]
where Int
is embedded in a nesting of types that all share some common
interface, such as Applicative
, Traversable
, or Foldable
.
It's necessary to turn on TypeApplications
so that you can supply a type argument that tells the compiler about the stack you are operating on.
You specify the stack by giving it's type with ()
as the embedded value. The ()
should be at the level
in the stack at which your target value is embedded.
Here is an example GHCi session:
>>>
:set -XTypeApplications
>>>
liftAll @[Maybe [()]] (+) [Just [3 :: Int]] [Just [6, 7]]
[Just [9,10]]>>>
data Foo = Foo Int String Double deriving Show
>>>
liftAll @[[()]] Foo [[2]] [["string"]] [[5]]
[[Foo 2 "string" 5.0]]>>>
fmapAll @[Maybe ()] length [Just "string"]
[Just 6]>>>
traverseAll @(Either String [()]) print (Right [1,2,3])
1 2 3 Right [(),(),()]
(Additional examples are in the haddocks.)
[Skip to Readme]
Properties
Versions | 1.0.0 |
---|---|
Change log | None available |
Dependencies | base (>=4.7 && <5) [details] |
License | BSD-3-Clause |
Copyright | 2020 Aaron Allen |
Author | Aaron Allen |
Maintainer | aaronallen8455@gmail.com |
Category | Control, Utils |
Home page | https://github.com/aaronallen8455/hydraulics#readme |
Source repo | head: git clone https://github.com/aaronallen8455/hydraulics |
Uploaded | by aaronallen8455 at 2020-01-03T05:35:59Z |
Modules
[Index]
- Control
Downloads
- hydraulics-1.0.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
Package maintainers
For package maintainers and hackage trustees