git.iko.soy/rowtype-yoga/purescript-yoga-variation
on main help sign in
9 files changed+272
since splitsnapshots
unifiedsplit
.github/workflows/ci.yml+24 .gitignore+10 README.md+1 package.json+20 packages.dhall+105 spago.dhall+14 src/Yoga/Variation/Variation.purs+75 test.dhall+12 test/Main.purs+11
.github/workflows/ci.ymlnew file+24
@@ -0,0 +1,24 @@
1+name: CI
2+
3+on: [push, pull_request]
4+
5+jobs:
6+ build:
7+ runs-on: ubuntu-latest
8+ steps:
9+ - uses: actions/checkout@v2
10+
11+ - uses: purescript-contrib/setup-purescript@main
12+
13+ - uses: actions/setup-node@v2
14+ with:
15+ node-version: "14"
16+
17+ - name: Install dependencies
18+ run: |
19+ npm install
20+ spago install
21+
22+ - name: Build source
23+ run: |
24+ spago build
.gitignorenew file+10
@@ -0,0 +1,10 @@
1+/bower_components/
2+/node_modules/
3+/.pulp-cache/
4+/output/
5+/generated-docs/
6+/.psc-package/
7+/.psc*
8+/.purs*
9+/.psa*
10+/.spago
README.md+1
@@ -1 +1,2 @@
11# purescript-yoga-variation
2+
package.jsonnew file+20
@@ -0,0 +1,20 @@
1+{
2+ "name": "purescript-yoga-variation",
3+ "version": "1.0.0",
4+ "description": "",
5+ "main": "index.js",
6+ "scripts": {
7+ "test": "echo \"Error: no test specified\" && exit 1"
8+ },
9+ "repository": {
10+ "type": "git",
11+ "url": "git+https://github.com/rowtype-yoga/purescript-yoga-variation.git"
12+ },
13+ "keywords": [],
14+ "author": "",
15+ "license": "ISC",
16+ "bugs": {
17+ "url": "https://github.com/rowtype-yoga/purescript-yoga-variation/issues"
18+ },
19+ "homepage": "https://github.com/rowtype-yoga/purescript-yoga-variation#readme"
20+}
packages.dhallnew file+105
@@ -0,0 +1,105 @@
1+{-
2+Welcome to your new Dhall package-set!
3+
4+Below are instructions for how to edit this file for most use
5+cases, so that you don't need to know Dhall to use it.
6+
7+## Use Cases
8+
9+Most will want to do one or both of these options:
10+1. Override/Patch a package's dependency
11+2. Add a package not already in the default package set
12+
13+This file will continue to work whether you use one or both options.
14+Instructions for each option are explained below.
15+
16+### Overriding/Patching a package
17+
18+Purpose:
19+- Change a package's dependency to a newer/older release than the
20+ default package set's release
21+- Use your own modified version of some dependency that may
22+ include new API, changed API, removed API by
23+ using your custom git repo of the library rather than
24+ the package set's repo
25+
26+Syntax:
27+where `entityName` is one of the following:
28+- dependencies
29+- repo
30+- version
31+-------------------------------
32+let upstream = --
33+in upstream
34+ with packageName.entityName = "new value"
35+-------------------------------
36+
37+Example:
38+-------------------------------
39+let upstream = --
40+in upstream
41+ with halogen.version = "master"
42+ with halogen.repo = "https://example.com/path/to/git/repo.git"
43+
44+ with halogen-vdom.version = "v4.0.0"
45+ with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies
46+-------------------------------
47+
48+### Additions
49+
50+Purpose:
51+- Add packages that aren't already included in the default package set
52+
53+Syntax:
54+where `<version>` is:
55+- a tag (i.e. "v4.0.0")
56+- a branch (i.e. "master")
57+- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977")
58+-------------------------------
59+let upstream = --
60+in upstream
61+ with new-package-name =
62+ { dependencies =
63+ [ "dependency1"
64+ , "dependency2"
65+ ]
66+ , repo =
67+ "https://example.com/path/to/git/repo.git"
68+ , version =
69+ "<version>"
70+ }
71+-------------------------------
72+
73+Example:
74+-------------------------------
75+let upstream = --
76+in upstream
77+ with benchotron =
78+ { dependencies =
79+ [ "arrays"
80+ , "exists"
81+ , "profunctor"
82+ , "strings"
83+ , "quickcheck"
84+ , "lcg"
85+ , "transformers"
86+ , "foldable-traversable"
87+ , "exceptions"
88+ , "node-fs"
89+ , "node-buffer"
90+ , "node-readline"
91+ , "datetime"
92+ , "now"
93+ ]
94+ , repo =
95+ "https://github.com/hdgarrood/purescript-benchotron.git"
96+ , version =
97+ "v7.0.0"
98+ }
99+-------------------------------
100+-}
101+let upstream =
102+ https://github.com/purescript/package-sets/releases/download/psc-0.15.2-20220531/packages.dhall
103+ sha256:278d3608439187e51136251ebf12fabda62d41ceb4bec9769312a08b56f853e3
104+
105+in upstream
spago.dhallnew file+14
@@ -0,0 +1,14 @@
1+{ name = "yoga-variation"
2+, dependencies =
3+ [ "arrays"
4+ , "bifunctors"
5+ , "console"
6+ , "effect"
7+ , "either"
8+ , "prelude"
9+ , "validation"
10+ , "variant"
11+ ]
12+, packages = ./packages.dhall
13+, sources = [ "src/**/*.purs", "test/**/*.purs" ]
14+}
src/Yoga/Variation/Variation.pursnew file+75
@@ -0,0 +1,75 @@
1+module Yoga.Variation.Variation
2+ ( Validated
3+ , fromEither
4+ , invalid
5+ , invalidM
6+ , key
7+ , mapErrors
8+ , module Validation
9+ , module Variant
10+ , valid
11+ , validM
12+ ) where
13+
14+import Prelude
15+
16+import Data.Array.NonEmpty (NonEmptyArray)
17+import Data.Array.NonEmpty as NonEmpty
18+import Data.Bifunctor (class Bifunctor, lmap)
19+import Data.Either (Either, either)
20+import Data.Symbol (class IsSymbol)
21+import Data.Validation.Semigroup as ValidationSG
22+import Data.Validation.Semigroup hiding (invalid) as Validation
23+import Data.Variant (class Contractable, class VariantBounded, class VariantBoundedEnums, class VariantEqs, class VariantMapCases, class VariantMatchCases, class VariantOrds, class VariantShows, class VariantTraverseCases, Unvariant(..), Unvariant', Variant, case_, contract, default, expand, inj, match, on, onMatch, over, overOne, overSome, prj, revariant, traverse, traverseOne, traverseSome, unvariant, variantBounded, variantBoundedEnums, variantEqs, variantOrds, variantShows) as Variant
24+import Prim.Row (class Cons, class Union)
25+import Prim.RowList (class RowToList)
26+import Type.Proxy (Proxy(..))
27+
28+type Validated err result = Validation.V (NonEmptyArray (Variant.Variant err)) result
29+
30+valid :: forall err result. result -> Validated err result
31+valid = pure
32+
33+validM :: forall m err result. Applicative m => result -> m (Validated err result)
34+validM = valid >>> pure
35+
36+invalid
37+ ∷ ∀ (result ∷ Type) (sym ∷ Symbol) (error ∷ Type) (others ∷ Row Type) (errors ∷ Row Type)
38+ . Cons sym error others errors
39+ ⇒ IsSymbol sym
40+ ⇒ Proxy sym
41+ → error
42+ → Validation.V (NonEmptyArray (Variant.Variant errors)) result
43+invalid proxy value = ValidationSG.invalid $ NonEmpty.singleton $ Variant.inj proxy value
44+
45+invalidM
46+ ∷ ∀ (result ∷ Type) (sym ∷ Symbol) (error ∷ Type) (others ∷ Row Type) (errors ∷ Row Type) m
47+ . Applicative m
48+ => Cons sym error others errors
49+ ⇒ IsSymbol sym
50+ ⇒ Proxy sym
51+ → error
52+ → m (Validation.V (NonEmptyArray (Variant.Variant errors)) result)
53+invalidM proxy = invalid proxy >>> pure
54+
55+fromEither
56+ :: ∀ (result ∷ Type) (sym ∷ Symbol) (error ∷ Type) (others ∷ Row Type) (errors ∷ Row Type)
57+ . Cons sym error others errors
58+ ⇒ IsSymbol sym
59+ ⇒ Proxy sym
60+ -> Either error result
61+ -> Validated errors result
62+fromEither proxy = either (invalid proxy) valid
63+
64+key ∷ ∀ (sym ∷ Symbol). Proxy sym
65+key = Proxy
66+
67+mapErrors
68+ :: forall result handlersRl handlers errorsRemaining errorsOut errorsIn
69+ . RowToList handlers handlersRl
70+ => Variant.VariantMatchCases handlersRl errorsRemaining (Variant.Variant errorsOut)
71+ => Union errorsRemaining errorsOut errorsIn
72+ => Record handlers
73+ -> Validated errorsIn result
74+ -> Validated errorsOut result
75+mapErrors handlers = lmap (map $ Variant.onMatch handlers identity)
test.dhallnew file+12
@@ -0,0 +1,12 @@
1+let conf = ./spago.dhall
2+
3+in conf
4+ // { sources = conf.sources # [ "test/**/*.purs" ]
5+ , dependencies =
6+ conf.dependencies
7+ # [ "aff"
8+ , "effect"
9+ , "spec"
10+ , "spec-discovery"
11+ ]
12+ }
test/Main.pursnew file+11
@@ -0,0 +1,11 @@
1+module Test.Main where
2+
3+import Prelude
4+
5+import Effect (Effect)
6+import Effect.Class.Console (log)
7+
8+main :: Effect Unit
9+main = do
10+ log "🍝"
11+ log "You should add some tests."