Commit 19fb7865 authored by root's avatar root
Browse files

Initial commit - v0.1.0.0

No related merge requests found
Pipeline #102 failed with stages
.stack-work/
*~
\ No newline at end of file
image: nixos/nix:latest
before_script:
- export LC_ALL=C.UTF-8
- nix-env -iA nixpkgs.stack
- nix-env -iA nixpkgs.hlint
stages:
- lint
- build
lint:
stage: lint
script:
- hlint .
build:
stage: build
script:
- stack --nix build --ghc-options "-Wall -Werror"
# Changelog for polysemy-extra
## v0.1.0.0
* Add several `Input`, `Output` and `KVStore` functions that I use..
Copyright Daniel Firth (c) 2020
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# polysemy-extra
This package provides some extra polysemy functions that I use for
transforming `Input`, `Output` and `KVStore`. Maybe this will make
its way into the main library.
name: polysemy-extra
version: 0.1.0.0
git: https://gitlab.com/homotopic-tech/polysemy-extra
license: MIT
author: "Daniel Firth"
maintainer: "dan.firth@homotopic.tech"
copyright: "2020 Daniel Firth"
extra-source-files:
- README.md
- ChangeLog.md
synopsis: Run a KVStore as a filesystem in polysemy.
category: Polysemy
dependencies:
- base >= 4.7 && < 5
- containers
- polysemy
- polysemy-zoo
library:
source-dirs: src
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.2.
--
-- see: https://github.com/sol/hpack
name: polysemy-extra
version: 0.1.0.0
synopsis: Run a KVStore as a filesystem in polysemy.
category: Polysemy
author: Daniel Firth
maintainer: dan.firth@homotopic.tech
copyright: 2020 Daniel Firth
license: MIT
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://gitlab.com/homotopic-tech/polysemy-extra
library
exposed-modules:
Polysemy.Extra
other-modules:
Paths_polysemy_extra
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, containers
, polysemy
, polysemy-zoo
default-language: Haskell2010
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Polysemy.Extra where
import Data.Map as Map
import Polysemy
import Polysemy.KVStore
import Polysemy.Input
import Polysemy.Output
-- | Run a KVStore in terms of another KVStore by way of pure key and value
-- transformations.
runKVStoreAsKVStore :: forall k v k' v' r a.
(k -> k')
-> (v -> v')
-> (v' -> v )
-> Sem (KVStore k v ': r) a
-> Sem (KVStore k' v' ': r) a
runKVStoreAsKVStore f g h = reinterpret \case
LookupKV k -> fmap h <$> lookupKV @k' @v' (f k)
UpdateKV k x -> updateKV @k' @v' (f k) (fmap g x)
-- | Run a KVStore in terms of another KVStore by way of transforming the
-- keys and values with Sem functions.
runKVStoreAsKVStoreSem :: forall k v k' v' r a.
Members '[KVStore k' v'] r
=> (k -> Sem r k')
-> (v -> Sem r v')
-> (v' -> Sem r v )
-> Sem (KVStore k v ': r) a
-> Sem r a
runKVStoreAsKVStoreSem f g h = interpret \case
LookupKV k -> f k >>= lookupKV @k' @v' >>= sequence . fmap h
UpdateKV k x -> do
z <- f k
z' <- sequence . fmap g $ x
updateKV @k' @v' z z'
-- | Run an `Output (Map k v)` as a `KVStore` by writing the values to
-- the keys.
runOutputMapAsKVStore :: Members '[ KVStore k v ] r
=> Sem (Output (Map k v) ': r) a
-> Sem r a
runOutputMapAsKVStore = interpret \case
Output xs -> mapM_ (uncurry writeKV) (Map.toList xs)
-- | Map an Output forwards
mapOutput :: Members '[ Output o' ] r
=> (o -> o')
-> Sem (Output o ': r) a
-> Sem r a
mapOutput f = interpret \case
Output o -> output (f o)
-- | Map an Output forwards through a monadic function.
mapOutputSem :: Members '[ Output o' ] r
=> (o -> Sem r o')
-> Sem (Output o ': r) a
-> Sem r a
mapOutputSem f = interpret \case
Output o -> f o >>= output
-- | Map an `Input` contravariantly.
contramapInput :: forall i i' r a.
Members '[ Input i' ] r
=> (i' -> i)
-> Sem (Input i ': r) a
-> Sem r a
contramapInput f = interpret \case
Input -> f <$> input @i'
-- | Map an `Input` contravariantly through a monadic function.
contramapInputSem :: forall i i' r a.
Members '[ Input i' ] r
=> (i' -> Sem r i)
-> Sem (Input i ': r) a
-> Sem r a
contramapInputSem f = interpret \case
Input -> f =<< input @i'
resolver: nightly-2020-10-29
packages:
- .
extra-deps:
- compact-0.2.0.0
- polysemy-zoo-0.7.0.1
- unliftio-path-0.0.2.0
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages:
- completed:
hackage: compact-0.2.0.0@sha256:9c5785bdc178ea6cf8f514ad35a78c64220e3cdb22216534e4cf496765551c7e,2345
pantry-tree:
size: 546
sha256: 6f7da573fbcddc109e1521edc07f1b34d7506473a3930074453e829daf901d71
original:
hackage: compact-0.2.0.0
- completed:
hackage: polysemy-zoo-0.7.0.1@sha256:60c2921df95f61d43222a75adde4f330e9510320b416132838a354cd81b4bcc5,3846
pantry-tree:
size: 2979
sha256: af39e295a7831e6bca01fa78df6c538cb6f1dfb339d118056fd0d9c314925726
original:
hackage: polysemy-zoo-0.7.0.1
- completed:
hackage: unliftio-path-0.0.2.0@sha256:cf4b02640b99831004853e8fc9f9ff922514d08a24ea36e09e8e7a77b250bc80,787
pantry-tree:
size: 281
sha256: 96fc899a5d4935c5eb8075e5f65a2c5eb046282ad9aac0fadcb3cbad9bdca164
original:
hackage: unliftio-path-0.0.2.0
snapshots:
- completed:
size: 543560
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/10/29.yaml
sha256: c8101bf4e679881fd9a6c8dcbdfc9586e119bdb2aad401f5c7e9bc0f8dac5622
original: nightly-2020-10-29
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment