git.iko.soy/rowtype-yoga/purescript-fallback
on main help sign in
Initial commit
commit292175170193ed97d4d1112b09db50d5d17cdf3a authorsigma-andex <77549848+sigma-andex@users.noreply.github.com> dateTue 5 Jul 2022, 17:06 (4 years ago) parentc26d87f
10 files changed+237
.gitignore+10 CHANGELOG.md+3 LICENSE+16 package.json+12 packages.dhall+105 spago.dhall+12 src/Fallback/Fallback.purs+19 test.dhall+13 test/Fallback/FallbackSpec.purs+33 test/Main.purs+14
.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
CHANGELOG.mdnew file+3
@@ -0,0 +1,3 @@
1+# Changelog
2+
3+TBA
LICENSEnew file+16
@@ -0,0 +1,16 @@
1+MIT No Attribution
2+
3+Copyright 2021 Jan Schulte
4+
5+Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+software and associated documentation files (the "Software"), to deal in the Software
7+without restriction, including without limitation the rights to use, copy, modify,
8+merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9+permit persons to whom the Software is furnished to do so.
10+
11+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
12+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
13+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
14+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
15+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
16+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package.jsonnew file+12
@@ -0,0 +1,12 @@
1+{
2+ "name": "purescript-fallback",
3+ "version": "1.0.0",
4+ "description": "",
5+ "main": "index.js",
6+ "scripts": {
7+ "test": "echo \"Error: no test specified\" && exit 1"
8+ },
9+ "keywords": [],
10+ "author": "",
11+ "license": "ISC"
12+}
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-20220630/packages.dhall
103+ sha256:691aff166010760f18ab1f4842ba6184f43747756e00579a050a2a46fa22d014
104+
105+in upstream
spago.dhallnew file+12
@@ -0,0 +1,12 @@
1+{ name = "fallback"
2+, dependencies =
3+ [ "console"
4+ , "effect"
5+ , "either"
6+ , "foldable-traversable"
7+ , "prelude"
8+ , "transformers"
9+ ]
10+, packages = ./packages.dhall
11+, sources = [ "src/**/*.purs", "test/**/*.purs" ]
12+}
src/Fallback/Fallback.pursnew file+19
@@ -0,0 +1,19 @@
1+module Fallback.Fallback where
2+
3+import Prelude
4+
5+import Control.Monad.Cont (ContT(..), lift, runContT)
6+import Control.Monad.Error.Class (class MonadError, try)
7+import Data.Either (either)
8+import Data.Traversable (class Traversable, sequence)
9+
10+fallback :: forall m e input output. MonadError e m => Traversable m => m input -> (e -> m output) -> ContT output m input
11+fallback ma errorHandler = try ma # sequence # either left right
12+ where
13+ left = \e -> ContT $ const $ errorHandler e
14+ right = lift
15+
16+withFallback :: forall output m. Applicative m => ContT output m output -> m output
17+withFallback = flip runContT (identity >>> pure)
18+
19+infixl 1 fallback as |>
test.dhallnew file+13
@@ -0,0 +1,13 @@
1+let conf = ./spago.dhall
2+
3+in conf
4+ // { sources = conf.sources # [ "test/**/*.purs" ]
5+ , dependencies =
6+ conf.dependencies
7+ # [ "spec"
8+ , "spec-discovery"
9+ , "integers"
10+ , "maybe"
11+ , "aff"
12+ ]
13+ }
test/Fallback/FallbackSpec.pursnew file+33
@@ -0,0 +1,33 @@
1+module Test.Fallback.FallbackSpec where
2+
3+import Prelude
4+
5+import Data.Int as Int
6+import Data.Maybe (Maybe(..))
7+import Fallback.Fallback (withFallback, (|>))
8+import Test.Spec (Spec, describe, it)
9+import Test.Spec.Assertions (shouldEqual)
10+
11+spec ∷ Spec Unit
12+spec = describe "Fallback" do
13+ it "fallback (1)" do
14+ let
15+ test = withFallback do
16+ i :: String <- Nothing |> const (Just 0)
17+ result <- Int.fromString i |> const (Just 1)
18+ pure result
19+ test `shouldEqual` (Just 0)
20+ it "fallback (2)" do
21+ let
22+ test = withFallback do
23+ i :: String <- Just "abc" |> const (Just 0)
24+ result <- Int.fromString i |> const (Just 1)
25+ pure result
26+ test `shouldEqual` (Just 1)
27+ it "fallback (3)" do
28+ let
29+ test = withFallback do
30+ i :: String <- Just "10" |> const (Just 0)
31+ result <- Int.fromString i |> const (Just 1)
32+ pure result
33+ test `shouldEqual` (Just 10)
test/Main.pursnew file+14
@@ -0,0 +1,14 @@
1+module Test.Main where
2+
3+import Prelude
4+
5+import Effect (Effect)
6+import Effect.Aff (launchAff_)
7+import Test.Spec.Discovery (discover)
8+import Test.Spec.Reporter (consoleReporter)
9+import Test.Spec.Runner (runSpec)
10+
11+main :: Effect Unit
12+main = launchAff_ $
13+ discover """\..*Spec"""
14+ >>= runSpec [ consoleReporter ]