mirror of
https://github.com/sharkdp/bat.git
synced 2025-07-15 21:45:17 +02:00
.github
assets
build
diagnostics
doc
examples
src
tests
benchmarks
examples
mocked-pagers
scripts
snapshots
syntax-tests
highlighted
source
ARM Assembly
ASP
AWK
ActionScript
Ada
Apache
AppleScript
AsciiDoc
Assembly (x86_64)
Bash
BatTestCustomAssets
Batch
BibTeX
C
C-Sharp
CFML
CMake
CSS
CSV
Cabal
Clojure
CoffeeScript
Cpp
CpuInfo
Crontab
Crystal
D
Dart
Diff
Dockerfile
DotENV
Elixir
Elm
Email
Erlang
EtcGroup
F#
Fish
Fortran (Fixed Form)
Fortran (Modern)
Fortran Namelist
Fstab
GLSL
Git Attributes
Git Config
Git Ignore
Go
GraphQL
Graphviz DOT
Groff
Groovy
HTML
Haskell
Hosts
INI
Ignored suffixes
JQ
JSON
Java
Java Server Page (JSP)
JavaScript
Jinja2
Julia
Kotlin
LLVM
Lean
Less
Lisp
Literate Haskell
LiveScript
Log
Lua
MATLAB
Makefile
Manpage
Markdown
MediaWiki
MemInfo
NAnt Build File
NSE
NSIS
Ninja
OCaml
Objective-C
Objective-C++
PHP
Pascal
Passwd
Perl
Plaintext
PowerShell
Protocol Buffer
Puppet
PureScript
test.purs
Python
QML
R
Racket
Rego
Regular Expression
Requirements.txt
Robot Framework
Ruby
Ruby Haml
Ruby On Rails
Rust
SCSS
SLS
SML
SQL
SSH Config
SSHD Config
Sass
Scala
Slim
Solidity
Strace
Stylus
Svelte
Swift
Syslog
SystemVerilog
TOML
Tcl
TeX
Terraform
Textile
Todo.txt
TypeScript
TypeScriptReact
Verilog
VimHelp
VimL
Vue
Vyper
WGSL
XAML
XML
YAML
Zig
cmd-help
dash
fish_history
gnuplot
http-request-response
jsonnet
nginx
nim
nix
orgmode
reStructuredText
resolv.conf
varlink
BatTestCustomAssets.sublime-syntax
compare_highlighted_versions.py
create_highlighted_versions.py
regression_test.sh
test_custom_assets.sh
update.sh
tester
utils
.gitattributes
assets.rs
github-actions.rs
integration_tests.rs
no_duplicate_extensions.rs
snapshot_tests.rs
system_wide_config.rs
test_pretty_printer.rs
.gitignore
.gitmodules
CHANGELOG.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
NOTICE
README.md
rustfmt.toml
90 lines
2.6 KiB
Plaintext
Vendored
90 lines
2.6 KiB
Plaintext
Vendored
-- | This module defines a datatype `Pair` together with a few useful instances
|
|
-- | and helper functions. Note that this is not just `Tuple a a` but rather a
|
|
-- | list with exactly two elements. Specifically, the `Functor` instance maps
|
|
-- | over both values (in contrast to the `Functor` instance for `Tuple a`).
|
|
module Data.Pair
|
|
( Pair(..)
|
|
, (~)
|
|
, fst
|
|
, snd
|
|
, curry
|
|
, uncurry
|
|
, swap
|
|
) where
|
|
|
|
import Prelude
|
|
|
|
import Data.Foldable (class Foldable)
|
|
import Data.Traversable (class Traversable)
|
|
import Data.Distributive (class Distributive)
|
|
|
|
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)
|
|
|
|
-- | A pair simply consists of two values of the same type.
|
|
data Pair a = Pair a a
|
|
|
|
infixl 6 Pair as ~
|
|
|
|
-- | Returns the first component of a pair.
|
|
fst ∷ ∀ a. Pair a → a
|
|
fst (x ~ _) = x
|
|
|
|
-- | Returns the second component of a pair.
|
|
snd ∷ ∀ a. Pair a → a
|
|
snd (_ ~ y) = y
|
|
|
|
-- | Turn a function that expects a pair into a function of two arguments.
|
|
curry ∷ ∀ a b. (Pair a → b) → a → a → b
|
|
curry f x y = f (x ~ y)
|
|
|
|
-- | Turn a function of two arguments into a function that expects a pair.
|
|
uncurry ∷ ∀ a b. (a → a → b) → Pair a → b
|
|
uncurry f (x ~ y) = f x y
|
|
|
|
-- | Exchange the two components of the pair
|
|
swap ∷ ∀ a. Pair a → Pair a
|
|
swap (x ~ y) = y ~ x
|
|
|
|
derive instance eqPair ∷ Eq a ⇒ Eq (Pair a)
|
|
|
|
derive instance ordPair ∷ Ord a ⇒ Ord (Pair a)
|
|
|
|
instance showPair ∷ Show a ⇒ Show (Pair a) where
|
|
show (x ~ y) = "(" <> show x <> " ~ " <> show y <> ")"
|
|
|
|
instance functorPair ∷ Functor Pair where
|
|
map f (x ~ y) = f x ~ f y
|
|
|
|
instance applyPair ∷ Apply Pair where
|
|
apply (f ~ g) (x ~ y) = f x ~ g y
|
|
|
|
instance applicativePair ∷ Applicative Pair where
|
|
pure x = x ~ x
|
|
|
|
instance bindPair ∷ Bind Pair where
|
|
bind (x ~ y) f = fst (f x) ~ snd (f y)
|
|
|
|
instance monadPair ∷ Monad Pair
|
|
|
|
instance semigroupPair ∷ Semigroup a ⇒ Semigroup (Pair a) where
|
|
append (x1 ~ y1) (x2 ~ y2) = (x1 <> x2) ~ (y1 <> y2)
|
|
|
|
instance monoidPair ∷ Monoid a ⇒ Monoid (Pair a) where
|
|
mempty = mempty ~ mempty
|
|
|
|
instance foldablePair ∷ Foldable Pair where
|
|
foldr f z (Pair x y) = x `f` (y `f` z)
|
|
foldl f z (Pair x y) = (z `f` x) `f` y
|
|
foldMap f (Pair x y) = f x <> f y
|
|
|
|
instance traversablePair ∷ Traversable Pair where
|
|
traverse f (Pair x y) = Pair <$> f x <*> f y
|
|
sequence (Pair mx my) = Pair <$> mx <*> my
|
|
|
|
instance distributivePair ∷ Distributive Pair where
|
|
distribute xs = map fst xs ~ map snd xs
|
|
collect f xs = map (fst <<< f) xs ~ map (snd <<< f) xs
|
|
|
|
instance arbitraryPair ∷ Arbitrary a ⇒ Arbitrary (Pair a) where
|
|
arbitrary = Pair <$> arbitrary <*> arbitrary
|