relude 1.0.0.1 → 1.2.2.2
raw patch · 62 files changed
Files
- CHANGELOG.md +274/−190
- README.md +201/−177
- benchmark/Main.hs +1/−2
- relude.cabal +41/−26
- src/Relude.hs +9/−8
- src/Relude/Applicative.hs +8/−7
- src/Relude/Base.hs +18/−9
- src/Relude/Bool.hs +8/−7
- src/Relude/Bool/Guard.hs +8/−7
- src/Relude/Bool/Reexport.hs +8/−7
- src/Relude/Container.hs +8/−7
- src/Relude/Container/One.hs +20/−18
- src/Relude/Container/Reexport.hs +8/−7
- src/Relude/Debug.hs +23/−32
- src/Relude/DeepSeq.hs +8/−7
- src/Relude/Enum.hs +9/−6
- src/Relude/Exception.hs +9/−16
- src/Relude/Extra.hs +14/−12
- src/Relude/Extra/Bifunctor.hs +6/−5
- src/Relude/Extra/CallStack.hs +6/−5
- src/Relude/Extra/Enum.hs +6/−5
- src/Relude/Extra/Foldable.hs +6/−5
- src/Relude/Extra/Foldable1.hs +17/−10
- src/Relude/Extra/Group.hs +9/−7
- src/Relude/Extra/Lens.hs +7/−7
- src/Relude/Extra/Map.hs +30/−7
- src/Relude/Extra/Newtype.hs +6/−10
- src/Relude/Extra/Tuple.hs +8/−7
- src/Relude/Extra/Type.hs +25/−7
- src/Relude/File.hs +17/−5
- src/Relude/Foldable.hs +6/−5
- src/Relude/Foldable/Fold.hs +17/−10
- src/Relude/Foldable/Reexport.hs +7/−6
- src/Relude/Function.hs +8/−7
- src/Relude/Functor.hs +8/−7
- src/Relude/Functor/Fmap.hs +8/−7
- src/Relude/Functor/Reexport.hs +13/−9
- src/Relude/Lifted.hs +23/−22
- src/Relude/Lifted/Concurrent.hs +8/−7
- src/Relude/Lifted/Env.hs +8/−5
- src/Relude/Lifted/Exit.hs +8/−7
- src/Relude/Lifted/File.hs +10/−7
- src/Relude/Lifted/Handle.hs +8/−5
- src/Relude/Lifted/IORef.hs +8/−7
- src/Relude/Lifted/Terminal.hs +6/−5
- src/Relude/List.hs +8/−7
- src/Relude/List/NonEmpty.hs +17/−7
- src/Relude/List/Reexport.hs +8/−7
- src/Relude/Monad.hs +11/−10
- src/Relude/Monad/Either.hs +9/−8
- src/Relude/Monad/Maybe.hs +12/−11
- src/Relude/Monad/Reexport.hs +16/−11
- src/Relude/Monad/Trans.hs +9/−8
- src/Relude/Monoid.hs +12/−11
- src/Relude/Nub.hs +25/−15
- src/Relude/Numeric.hs +6/−5
- src/Relude/Print.hs +8/−7
- src/Relude/String.hs +8/−8
- src/Relude/String/Conversion.hs +23/−8
- src/Relude/String/Reexport.hs +17/−7
- src/Relude/Unsafe.hs +10/−9
- test/Doctest.hs +2/−1
CHANGELOG.md view
@@ -3,19 +3,90 @@ `relude` uses [PVP Versioning][1]. The changelog is available [on GitHub][2]. +## 1.2.2.2 – Aug 5, 2025++- Documentation improvements++## 1.2.2.1 – Jul 29, 2025++- Allow containers-0.8.++- Documentation improvements++## 1.2.2.0 – Oct 13, 2024++- Support GHC-9.10 & GHC-9.8.+- Allow hashable-1.5++## 1.2.1.0 – Oct 4, 2023++- [#439](https://github.com/kowainik/relude/issues/439):+ Support GHC-9.6.+- Upgrade dependencies. Allow:+ - `ghc-prim-0.10`+ - `text-2.1`+ - `bytestring-2.12`+ - `containers-0.7`+ - `deepseq-1.5`+ - `hedgehod-1.3`+ - `doctest-0.22`+- Upgrade tests to work with GHC-9.6.++## 1.2.0.0 – Mar 1, 2023++- [#420](https://github.com/kowainik/relude/issues/420):+ Support GHC-9.4.+- Reexport `type (~)` from `Data.Type.Equality` for GHC-9.4.+- Add `-Wredundant-strictness-flags` and `-Wforall-identifier` warnings for+ GHC-9.4.+- [#430](https://github.com/kowainik/relude/issues/430):+ Upgrade dependencies:+ - `ghc-prim-0.9`+ - `mtl-2.3`+ - `hedgehog-1.2`+ - `doctest-0.21`+- Drop support of GHC-8.2.++## 1.1.0.0 — Jun 9, 2022++- [#388](https://github.com/kowainik/relude/issues/388):+ Support GHC-9.2.+- [#363](https://github.com/kowainik/relude/issues/363):+ Remove the `Option` type, reexported from `Data.Semigroup`+ (which was removed in `base-4.16`, GHC 9.2)++ **Migration guide:** Use `Maybe` instead of `Option`.++- [#372](https://github.com/kowainik/relude/issues/372):+ Warn on usages of `readFileText`, `readFileLText`, `readFile` and `readFile'`.++ > _NOTE:_ This is a **breaking change** if you build with `-Werror`+ > and use the above functions. Use `readFileBS` / `readFileLBS`+ > instead to convert to `Text` / `LText` / `String` using+ > `decodeUtf8` and similar functions.++- [#394](https://github.com/kowainik/relude/issues/394):+ Support `hashable-1.4`.+- [#408](https://github.com/kowainik/relude/issues/408):+ Switch benchmarks from `criterion` to `tasty-bench`.+- [#404](https://github.com/kowainik/relude/issues/404):+ Fix condidion for `ordNubOn`, `intNub`, `intNubOn` export for `Relude.Nub` module.+ Use min version of `containers-0.6.0` instead of min version of GHC `8.4`.+- Minor documentation improvements and fixes.+ ## 1.0.0.1 — Mar 15, 2021 -* Minor documentation changes.+- Minor documentation changes. ## 1.0.0.0 — Mar 12, 2021 -* [#353](https://github.com/kowainik/relude/issues/353):+- [#353](https://github.com/kowainik/relude/issues/353): Reexport most common modules from the following libraries: - + `containers`- + `unordered-containers`- + `text`- + `bytestring`+ - `containers`+ - `unordered-containers`+ - `text`+ - `bytestring` Now, when using `relude`, you don't need to add these libraries to your `.cabal` file to enjoy their main API. Try removing them from@@ -31,158 +102,164 @@ , relude ``` -* [#345](https://github.com/kowainik/relude/issues/345):+- [#345](https://github.com/kowainik/relude/issues/345): Support GHC-9.0.-* Upgrade minor GHC versions to GHC-8.10.4 and GHC-8.8.4.-* [#268](https://github.com/kowainik/relude/issues/268):+- Upgrade minor GHC versions to GHC-8.10.4 and GHC-8.8.4.+- [#268](https://github.com/kowainik/relude/issues/268): Drop support of GHC-8.0.2.-* [#270](https://github.com/kowainik/relude/issues/270):+- [#270](https://github.com/kowainik/relude/issues/270): Standardise `universe`, `universeNonEmpty` and `inverseMap` functions that previously were introduced in the `Relude.Extra.Enum` module. `Relude.Enum` module created that is exported in the main `Relude` module by default. - __Migration guide:__ If you were using any of these functions you can now+ **Migration guide:** If you were using any of these functions you can now remove `Relude.Extra.Enum` from your imports and explicit `mixins` section as they are available for you with the `Relude` module.-* Remove the `Eq` constraint on `universeNonEmpty`-* [#269](https://github.com/kowainik/relude/issues/269):++- Remove the `Eq` constraint on `universeNonEmpty`+- [#269](https://github.com/kowainik/relude/issues/269): Remove the `Relude.Extra.Validation` module. - __Migration guide:__+ **Migration guide:** If you use `Relude.Extra.Validation` in you project you need to: - 1. Add `validation-selective` into the `build-depends` section of your- `.cabal` file.- 2. Change imports of `Relude.Extra.Validation` to `Validation`:+ 1. Add `validation-selective` into the `build-depends` section of your+ `.cabal` file.+ 2. Change imports of `Relude.Extra.Validation` to `Validation`: - ```haskell- -- Was:- import Relude.Extra.Validation (Validation (..), ..)- -- Became:- import Validation (Validation (..), ..)- ```+ ```haskell+ -- Was:+ import Relude.Extra.Validation (Validation (..), ..)+ -- Became:+ import Validation (Validation (..), ..)+ ``` -* [#346](https://github.com/kowainik/relude/issues/346),+- [#346](https://github.com/kowainik/relude/issues/346), [#347](https://github.com/kowainik/relude/issues/347): Reimplement `ordNub` through `nubOrd` from `containers`. Add `ordNubOn`, `intNub` and `intNubOn` functions.-* [#327](https://github.com/kowainik/relude/issues/327):+- [#327](https://github.com/kowainik/relude/issues/327): Add `infinitely` as more strictly typed `forever`.-* [#311](https://github.com/kowainik/relude/issues/311):+- [#311](https://github.com/kowainik/relude/issues/311): Add `maybeAt` function — the non-operator version of `!!?` with its arguments flipped.-* [#314](https://github.com/kowainik/relude/issues/314):+- [#314](https://github.com/kowainik/relude/issues/314): Add lifted versions of functions to work with `Handle`: - + `hFlush`- + `hIsEOF`- + `hSetBuffering`- + `hGetBuffering`-* [#305](https://github.com/kowainik/relude/issues/305):+ - `hFlush`+ - `hIsEOF`+ - `hSetBuffering`+ - `hGetBuffering`++- [#305](https://github.com/kowainik/relude/issues/305): Add lifted versions of functions to work with environment: - + `getArgs`- + `lookupEnv`-* Add lifted version of the `readFile'` function.-* Reexport the `BufferMode` type from `base`.-* [#309](https://github.com/kowainik/relude/issues/309):+ - `getArgs`+ - `lookupEnv`++- Add lifted version of the `readFile'` function.+- Reexport the `BufferMode` type from `base`.+- [#309](https://github.com/kowainik/relude/issues/309): Reexport `span` from `Data.List`.-* [#319](https://github.com/kowainik/relude/issues/319):+- [#319](https://github.com/kowainik/relude/issues/319): Implement `partitionWith`.-* [#307](https://github.com/kowainik/relude/issues/307):+- [#307](https://github.com/kowainik/relude/issues/307): Add `foldr1` to `Foldable1`.-* [#316](https://github.com/kowainik/relude/issues/316):+- [#316](https://github.com/kowainik/relude/issues/316): Add `average` and `average1` — efficient functions for finding average on foldable structures.-* [#306](https://github.com/kowainik/relude/issues/306):+- [#306](https://github.com/kowainik/relude/issues/306): Add `maximumOn1` and `minimumOn1` to `Foldable1`.-* [#301](https://github.com/kowainik/relude/issues/301):+- [#301](https://github.com/kowainik/relude/issues/301): Add `traceShowWith` to `Relude.Debug`.-* [#304](https://github.com/kowainik/relude/issues/304),+- [#304](https://github.com/kowainik/relude/issues/304), [#317](https://github.com/kowainik/relude/issues/317): Various documentation improvements.-* Updates to `relude`-specific `.hlint` rules.+- Updates to `relude`-specific `.hlint` rules. Thanks @googleson78, @sushi-shi, @rektrex, @aleator, @mjgpy3, @dalpd, @Bodigrim for helping with this release! ## 0.7.0.0 — May 14, 2020 -* [#253](https://github.com/kowainik/relude/issues/253):+- [#253](https://github.com/kowainik/relude/issues/253): Support GHC-8.10. Upgrade GHC-8.8 to 8.8.3.-* Significant documentation improvements:- + Add high-level description to each reexported module.- + Add String Conversion Table.- + Add `NonEmpty` lists functions tables.- + Add `@since` annotations.- + Improve README.- + Inline some external reexports into explicit lists of exports.- + Rewrite top-level `cabal` description.-* [#234](https://github.com/kowainik/relude/issues/234):+- Significant documentation improvements:+ - Add high-level description to each reexported module.+ - Add String Conversion Table.+ - Add `NonEmpty` lists functions tables.+ - Add `@since` annotations.+ - Improve README.+ - Inline some external reexports into explicit lists of exports.+ - Rewrite top-level `cabal` description.+- [#234](https://github.com/kowainik/relude/issues/234): Reexport `scanl1`, `scanr1`, `scanl'` from `Data.List`.-* [#256](https://github.com/kowainik/relude/issues/256):+- [#256](https://github.com/kowainik/relude/issues/256): Make `cycle` total function.-* [#233](https://github.com/kowainik/relude/issues/233):+- [#233](https://github.com/kowainik/relude/issues/233): Add `etaReaderT` to `Relude.Monad.Trans` to help with performance.-* [#294](https://github.com/kowainik/relude/issues/294):+- [#294](https://github.com/kowainik/relude/issues/294): Add `atomicModifyIORef_` and `atomicModifyIORef'_`.-* [#293](https://github.com/kowainik/relude/issues/293):+- [#293](https://github.com/kowainik/relude/issues/293): Add `memptyIfFalse` and `memptyIfTrue` functions.-* Reexport `NonEmpty` functions from `Relude.List.NonEmpty` instead of+- Reexport `NonEmpty` functions from `Relude.List.NonEmpty` instead of `Relude.List.Reexport`.-* [#239](https://github.com/kowainik/relude/issues/239):+- [#239](https://github.com/kowainik/relude/issues/239): Reexport more STM functions that work with `TMVar` from `Relude.Lifted.Concurrent`.-* [#227](https://github.com/kowainik/relude/issues/227):+- [#227](https://github.com/kowainik/relude/issues/227): Create `Relude.Extra` module-* [#228](https://github.com/kowainik/relude/issues/228):+- [#228](https://github.com/kowainik/relude/issues/228): Add `universeNonEmpty` function.-* [#249](https://github.com/kowainik/relude/issues/249):- __Breaking change:__ Fix infix of the `Relude.Extra.Lens` `(^.)` operator.+- [#249](https://github.com/kowainik/relude/issues/249):+ **Breaking change:** Fix infix of the `Relude.Extra.Lens` `(^.)` operator. Change it to `infixl 8`.-* Reexport partial `read` from `Relude.Unsafe` for consistency.-* [#244](https://github.com/kowainik/relude/issues/244):+- Reexport partial `read` from `Relude.Unsafe` for consistency.+- [#244](https://github.com/kowainik/relude/issues/244): Remove deprecated functions: `prec`, `dupe` and `mapBoth`. - __Migration rules:__- + `prec`: use `prev` instead- + `dupe`: use `dup` instead- + `mapBoth`: use `bimapBoth` instead+ **Migration rules:** -* [#246](https://github.com/kowainik/relude/issues/246):+ - `prec`: use `prev` instead+ - `dupe`: use `dup` instead+ - `mapBoth`: use `bimapBoth` instead++- [#246](https://github.com/kowainik/relude/issues/246): Deprecate `Relude.Extra.Validation` in favour of [`validation-selective`](https://hackage.haskell.org/package/validation-selective) - __Migration rules:__+ **Migration rules:** If you use `Relude.Extra.Validation` in you project you need to: - 1. Add `validation-selective` into the `build-depends` section of your- `.cabal` file.- 2. Change imports of `Relude.Extra.Validation` to `Validation`:+ 1. Add `validation-selective` into the `build-depends` section of your+ `.cabal` file.+ 2. Change imports of `Relude.Extra.Validation` to `Validation`: - ```haskell- -- Was:- import Relude.Extra.Validation (Validation (..), ..)- -- Became:- import Validation (Validation (..), ..)- ```-* [#196](https://github.com/kowainik/relude/issues/196):+ ```haskell+ -- Was:+ import Relude.Extra.Validation (Validation (..), ..)+ -- Became:+ import Validation (Validation (..), ..)+ ```++- [#196](https://github.com/kowainik/relude/issues/196): Deprecate `mapToFst` and `mapToSnd`. Introduce `toFst` and `toSnd` in `Relude.Extra.Tuple` as shorter aliases for `mapToFst`. Implement `fmapToFst` and `fmapToSnd`. Add more HLint rules for `Relude.Extra.Tuple` functions. - __Migration rules:__+ **Migration rules:** - + Replace `mapToFst` with `toFst`- + Replace `mapToSnd` with `toSnd`- + You can now use `fmapToFst` and `fmapToSnd` instead of+ - Replace `mapToFst` with `toFst`+ - Replace `mapToSnd` with `toSnd`+ - You can now use `fmapToFst` and `fmapToSnd` instead of `[f]map (mapToFst f)` and `[f]map (mapToSnd f)`-* [#286](https://github.com/kowainik/relude/issues/286):- __Breaking change:__ `readEither` is not polymorphic over the first argument++- [#286](https://github.com/kowainik/relude/issues/286):+ **Breaking change:** `readEither` is not polymorphic over the first argument anymore. Now it takes `String`. - __Migration rules:__ Use one of the conversion function from the+ **Migration rules:** Use one of the conversion function from the `Relude.String.Conversion` module to covert your old input value into `String`. @@ -198,92 +275,96 @@ readEither @Int (toString myText) ``` -* [#281](https://github.com/kowainik/relude/issues/281):+- [#281](https://github.com/kowainik/relude/issues/281): Move `One` property tests from `doctest` to `hedgehog`. Significant test time boost.-* [#264](https://github.com/kowainik/relude/issues/264):+- [#264](https://github.com/kowainik/relude/issues/264): Support Dhall-16.0.0 in HLint rules. ## 0.6.0.0 — Oct 30, 2019 -* [#171](https://github.com/kowainik/relude/issues/171):+- [#171](https://github.com/kowainik/relude/issues/171): Add custom type errors to various functions and instances.- + `head`, `tail`, `last`, `init`- + `words`, `unwords`, `lines`, `unlines`- + `error`- + `ToText`, `ToLText`, `ToString` instances for bytestrings- + `Foldable1` instance for ordinary lists- + `Monad` instance for `Validation` + - `head`, `tail`, `last`, `init`+ - `words`, `unwords`, `lines`, `unlines`+ - `error`+ - `ToText`, `ToLText`, `ToString` instances for bytestrings+ - `Foldable1` instance for ordinary lists+ - `Monad` instance for `Validation`+ (by [@vrom911](https://github.com/vrom911), [@chshersh](https://github.com/chshersh))-* [#164](https://github.com/kowainik/relude/issues/164):++- [#164](https://github.com/kowainik/relude/issues/164): Reexport `ShortByteString`, `toShort`/`fromShort` functions. (by [@vrom911](https://github.com/vrom911))-* [#182](https://github.com/kowainik/relude/issues/182):+- [#182](https://github.com/kowainik/relude/issues/182): Support GHC-8.8.1. (by [@chshersh](https://github.com/chshersh))-* [#168](https://github.com/kowainik/relude/pull/168),+- [#168](https://github.com/kowainik/relude/pull/168), [#197](https://github.com/kowainik/relude/pull/197): Improve documentation significantly (more and better examples, better wording). (by [@chshersh](https://github.com/chshersh), [@vrom911](https://github.com/vrom911), [@Cmdv](https://github.com/Cmdv))-* [#177](https://github.com/kowainik/relude/issues/177):+- [#177](https://github.com/kowainik/relude/issues/177): Improve usage of performance pragmas. (by [@chshersh](https://github.com/chshersh))-* [#167](https://github.com/kowainik/relude/issues/167):+- [#167](https://github.com/kowainik/relude/issues/167): Rename functions (and deprecate old versions):- + `prec` to `prev`- + `dupe` to `dup` + - `prec` to `prev`+ - `dupe` to `dup`+ (by [@Cmdv](https://github.com/Cmdv), [@chshersh](https://github.com/chshersh))-* [#192](https://github.com/kowainik/relude/issues/192):++- [#192](https://github.com/kowainik/relude/issues/192): Reexport `foldMap'` from `Data.Foldable`. (by [@tfausak](https://github.com/tfausak))-* [#201](https://github.com/kowainik/relude/issues/201):+- [#201](https://github.com/kowainik/relude/issues/201): Implement `!!?` as a safe equivalent of `!!` that returns a `Maybe`. (by [@kutyel](https://github.com/kutyel))-* [#203](https://github.com/kowainik/relude/issues/203):+- [#203](https://github.com/kowainik/relude/issues/203): Implement the `guarded` combinator. (by [@JonathanLorimer](https://github.com/JonathanLorimer))-* [#214](https://github.com/kowainik/relude/issues/214):+- [#214](https://github.com/kowainik/relude/issues/214): Add `mapMaybeM` function. (by [@vrom911](https://github.com/vrom911))-* [#174](https://github.com/kowainik/relude/issues/174):+- [#174](https://github.com/kowainik/relude/issues/174): Implement `bimapBoth` in `Relude.Extra.Tuple` module, mark `mapBoth` as DEPRECATED. (by [@astynax](https://github.com/astynax))-* [#221](https://github.com/kowainik/relude/issues/221):+- [#221](https://github.com/kowainik/relude/issues/221): Improve documentation for the `Validation` module significantly. (by [@chshersh](https://github.com/chshersh))-* [#176](https://github.com/kowainik/relude/issues/176):+- [#176](https://github.com/kowainik/relude/issues/176): Implement property-based tests for `Validation` laws. (by [@astynax](https://github.com/astynax))-* [#172](https://github.com/kowainik/relude/issues/172):+- [#172](https://github.com/kowainik/relude/issues/172): Add `Monoid` and `Semigroup` instances for the `Validation` type. (by [@mauriciofierrom](https://github.com/mauriciofierrom))-* [#156](https://github.com/kowainik/relude/issues/156):+- [#156](https://github.com/kowainik/relude/issues/156): Implement helper type-level functions in `Relude.Extra.Type`. (by [@TheMatten](https://github.com/TheMatten))-* [#170](https://github.com/kowainik/relude/issues/170):+- [#170](https://github.com/kowainik/relude/issues/170): Implement `Elem` type family. (by [@kutyel](https://github.com/kutyel))-* [#165](https://github.com/kowainik/relude/pull/165):+- [#165](https://github.com/kowainik/relude/pull/165): Re-export `GHC.Float.atan2`. (by [@ethercrow](https://github.com/ethercrow))-* [#155](https://github.com/kowainik/relude/issue/155):+- [#155](https://github.com/kowainik/relude/issue/155): Implement `foldlSC` — short-circuting list fold — in `Relude.Extra.Foldable`. (by [@josephcsible](https://github.com/josephcsible))-* [#158](https://github.com/kowainik/relude/issue/158):+- [#158](https://github.com/kowainik/relude/issue/158): Support GHC-8.6.5. (by [@chshersh](https://github.com/chshersh))-* [#148](https://github.com/kowainik/relude/issues/148):+- [#148](https://github.com/kowainik/relude/issues/148): Migrate HLint rules to the latest Dhall spec. (by [@vrom911](https://github.com/vrom911))-* [#178](https://github.com/kowainik/relude/issues/178):+- [#178](https://github.com/kowainik/relude/issues/178): Made `die` be polymorphic in its return type. (by [@ilyakooo0](https://github.com/ilyakooo0))-* [#162](https://github.com/kowainik/relude/pull/162),+- [#162](https://github.com/kowainik/relude/pull/162), [#189](https://github.com/kowainik/relude/pull/189), [#190](https://github.com/kowainik/relude/pull/190), [#191](https://github.com/kowainik/relude/pull/191),@@ -291,83 +372,85 @@ [#194](https://github.com/kowainik/relude/pull/194), [#195](https://github.com/kowainik/relude/pull/195): Various refactorings and code improvements:- + __Breaking change:__ Reorder type parameters to `asumMap`- + Implement `andM`, `orM`, `allM`, and `anyM` in terms of `&&^` and `||^`- + Use `foldr` instead of explicit recursion and `toList`- + Use `mapToFst` instead of `zip` to improve list fusion in `inverseMap`- + Implement `foldMap1` for `NonEmpty` in terms of `foldr`- + Use `$>` instead of `*>` and `pure` where possible- + Implement `asumMap` and `foldMapA` by coercing `foldMap`- + Return Failure early in `<*` and `*>` too + - **Breaking change:** Reorder type parameters to `asumMap`+ - Implement `andM`, `orM`, `allM`, and `anyM` in terms of `&&^` and `||^`+ - Use `foldr` instead of explicit recursion and `toList`+ - Use `mapToFst` instead of `zip` to improve list fusion in `inverseMap`+ - Implement `foldMap1` for `NonEmpty` in terms of `foldr`+ - Use `$>` instead of `*>` and `pure` where possible+ - Implement `asumMap` and `foldMapA` by coercing `foldMap`+ - Return Failure early in `<*` and `*>` too+ (by [@josephcsible](https://github.com/josephcsible))-* [#187](https://github.com/kowainik/relude/issues/187):++- [#187](https://github.com/kowainik/relude/issues/187): Remove `tasty` and `tasty-hedgehog` dependencies and their redundant imports. (by [@dalpd](https://github.com/dalpd)) ## 0.5.0 — Mar 18, 2019 -* [#127](https://github.com/kowainik/relude/issues/127):+- [#127](https://github.com/kowainik/relude/issues/127): Implement `Relude.Extra.Lens` module.-* [#125](https://github.com/kowainik/relude/issues/125):+- [#125](https://github.com/kowainik/relude/issues/125): Moved many numerical functions and types in `Relude.Numeric`. Reexport `toIntegralSized` from `Data.Bits`. Add `integerToBounded` and `integerToNatural` in `Relude.Numeric`.-* [#121](https://github.com/kowainik/relude/issues/121):+- [#121](https://github.com/kowainik/relude/issues/121): Reexport `Ap` from `Data.Monoid`. Change definition of `foldMapA` to use `Ap`.-* [#129](https://github.com/kowainik/relude/issues/129):+- [#129](https://github.com/kowainik/relude/issues/129): Add `appliedTo` and `chainedTo` as named versions of operators `=<<` and `<**>`.-* [#138](https://github.com/kowainik/relude/issues/138):+- [#138](https://github.com/kowainik/relude/issues/138): Add `RealFloat` to `Relude.Numeric`.-* [#144](https://github.com/kowainik/relude/issues/144):+- [#144](https://github.com/kowainik/relude/issues/144): Add `traverseToSnd` and friends to `Relude.Extra.Tuple`.-* [#140](https://github.com/kowainik/relude/issues/140):+- [#140](https://github.com/kowainik/relude/issues/140): Improve text of custom compile-time error messages for `elem` functions.-* [#136](https://github.com/kowainik/relude/issues/136):+- [#136](https://github.com/kowainik/relude/issues/136): Cover `Relude.Extra.*` modules with custom HLint rules.-* [#146](https://github.com/kowainik/relude/issues/146):+- [#146](https://github.com/kowainik/relude/issues/146): Improve documentation for `Relude.File` file: be more explicit about system locale issues.-* Improve documentation for `One` typeclass and add tests.-* Support ghc-8.6.4 and ghc-8.4.4.+- Improve documentation for `One` typeclass and add tests.+- Support ghc-8.6.4 and ghc-8.4.4. Drop support for ghc-8.6.1 and ghc-8.4.3. ## 0.4.0 — Nov 6, 2018 -* [#70](https://github.com/kowainik/relude/issues/70):+- [#70](https://github.com/kowainik/relude/issues/70): Reexport `Contravariant` for GHC >= 8.6.1.-* [#103](https://github.com/kowainik/relude/pull/104):+- [#103](https://github.com/kowainik/relude/pull/104): Drop `utf8-string` dependency and improve performance of conversion functions.-* [#98](https://github.com/kowainik/relude/issues/98):+- [#98](https://github.com/kowainik/relude/issues/98): Reexport `Bifoldable` related stuff from `base`.-* [#99](https://github.com/kowainik/relude/issues/99):+- [#99](https://github.com/kowainik/relude/issues/99): Reexport `Bitraversable` related stuff from `base`.-* [#100](https://github.com/kowainik/relude/issues/100):+- [#100](https://github.com/kowainik/relude/issues/100): Add `Relude.Extra.Validation` with `Validation`data type.-* [#89](https://github.com/kowainik/relude/issues/89):+- [#89](https://github.com/kowainik/relude/issues/89): Add `Relude.Extra.Type` module containing a `typeName` function.-* [#92](https://github.com/kowainik/relude/issues/92)+- [#92](https://github.com/kowainik/relude/issues/92) Add `Relude.Extra.Tuple` module, containing `dupe`, `mapToFst`, `mapToSnd`, and `mapBoth` functions.-* [#97](https://github.com/kowainik/relude/issues/97):+- [#97](https://github.com/kowainik/relude/issues/97): Add `(&&^)` and `(||^)` operators.-* [#81](https://github.com/kowainik/relude/issues/81):+- [#81](https://github.com/kowainik/relude/issues/81): Add `asumMap` to `Foldable` functions.-* [#80](https://github.com/kowainik/relude/issues/80):+- [#80](https://github.com/kowainik/relude/issues/80): Add hlint rules for `whenLeft`, `whenLeftM`, `whenRight` and `whenRightM`.-* [#79](https://github.com/kowainik/relude/issues/79):+- [#79](https://github.com/kowainik/relude/issues/79): Add HLint rules for `One` typeclass.-* Remove `openFile` and `hClose`.-* [#83](https://github.com/kowainik/relude/pull/83):+- Remove `openFile` and `hClose`.+- [#83](https://github.com/kowainik/relude/pull/83): Make documentation for `nub` functions prettier.-* [#109](https://github.com/kowainik/relude/issues/109):+- [#109](https://github.com/kowainik/relude/issues/109): Use Dhall v3.0.0 for hlint file generation. ## 0.3.0 -* [#41](https://github.com/kowainik/relude/issues/41):+- [#41](https://github.com/kowainik/relude/issues/41): Add `Foldable1`.-* [#63](https://github.com/kowainik/relude/issues/63):+- [#63](https://github.com/kowainik/relude/issues/63): Remove `Print` typeclass. Add `put[L]BS[Ln]` functions. `trace` functions now take `String` as argument instead of `Text`.@@ -375,41 +458,42 @@ **Important:** this is a breaking change. If you used polymorphic `putStrLn` you need to remove type application or switch to one of the monomorphic functions. Also, you can't abstract over `Print` typeclass anymore.-* [#66](https://github.com/kowainik/relude/issues/66):++- [#66](https://github.com/kowainik/relude/issues/66): Export `(>>>)` and `(<<<)` from `Control.Category`.-* [#59](https://github.com/kowainik/relude/issues/59):+- [#59](https://github.com/kowainik/relude/issues/59): Introduce `flap` function and its operator version `??`.-* [#64](https://github.com/kowainik/relude/issues/64):+- [#64](https://github.com/kowainik/relude/issues/64): Improve performance of functions from `Foldable1`. Add `foldl1'` function.-* Reexport `uncons` from `base`.-* Rewrite `die` implementation to use `die` from `base`.-* [#19](https://github.com/kowainik/relude/issues/19):+- Reexport `uncons` from `base`.+- Rewrite `die` implementation to use `die` from `base`.+- [#19](https://github.com/kowainik/relude/issues/19): Rewrite `.hlint.yaml` to Dhall.-* Move `stdin`- and `stdout`-related functions to new module `Relude.Lifted.Terminal`.-* [#67](https://github.com/kowainik/relude/issues/67):+- Move `stdin`- and `stdout`-related functions to new module `Relude.Lifted.Terminal`.+- [#67](https://github.com/kowainik/relude/issues/67): Add HLint rules for `put*` functions.-* [#22](https://github.com/kowainik/relude/issues/22):+- [#22](https://github.com/kowainik/relude/issues/22): `readFile`, `writeFile` and `appendFile` now work with `String`. Add lifted version of `hClose`. Add `readFile`, `writeFile` and `appendFile` alternatives for `Text` and `ByteString`.-* [#61](https://github.com/kowainik/relude/issues/61):+- [#61](https://github.com/kowainik/relude/issues/61): Add `under2` and `underF2` functions to `Relude.Extra.Newtype`.-* [#60](https://github.com/kowainik/relude/issues/60):+- [#60](https://github.com/kowainik/relude/issues/60): Add `hoistMaybe` and `hoistEither` functions. ## 0.2.0 -* [#43](https://github.com/kowainik/relude/issues/43):+- [#43](https://github.com/kowainik/relude/issues/43): Implement `Relude.Extra.Newtype` module.-* [#46](https://github.com/kowainik/relude/issues/46):+- [#46](https://github.com/kowainik/relude/issues/46): Add a function that returns its own name.-* [#48](https://github.com/kowainik/relude/issues/48):+- [#48](https://github.com/kowainik/relude/issues/48): Export `<&>` from `base`. Also reexport `fromLeft` and `fromRight` from `base` where possible.-* [#49](https://github.com/kowainik/relude/issues/49):+- [#49](https://github.com/kowainik/relude/issues/49): Speed up and refactor property tests.-* [#54](https://github.com/kowainik/relude/issues/54):+- [#54](https://github.com/kowainik/relude/issues/54): Improve documentation. Add more examples to documentation and more tests. Reexport `withReader` and `withReaderT`.@@ -418,48 +502,48 @@ ## 0.1.1 -* [#44](https://github.com/kowainik/relude/issues/44):+- [#44](https://github.com/kowainik/relude/issues/44): Implement parser deriviation from pretty-printers. ## 0.1.0 -* [#7](https://github.com/kowainik/relude/issues/7):+- [#7](https://github.com/kowainik/relude/issues/7): Remove `Container.Class.Container`. Export `Foldable`.-* [#2](https://github.com/kowainik/relude/issues/2):+- [#2](https://github.com/kowainik/relude/issues/2): Remove `microlens` from dependencies.-* [#10](https://github.com/kowainik/relude/issues/10):+- [#10](https://github.com/kowainik/relude/issues/10): Remove `VarArg` module.-* [#9](https://github.com/kowainik/relude/issues/9):+- [#9](https://github.com/kowainik/relude/issues/9): Remove `safe-exceptions` from dependencies. Reexport `Exception` and `SomeException` from `Control.Exception` instead.-* [#11](https://github.com/kowainik/relude/issues/11):+- [#11](https://github.com/kowainik/relude/issues/11): Remove `TypeOps` module and `type-operators` dependency.-* [#13](https://github.com/kowainik/relude/issues/13):+- [#13](https://github.com/kowainik/relude/issues/13): Remove `list`, `getContents`, `interact`, `getArgs`, `note` functions. Remove `Lifted.ST` module. Rename `Lifted.Env` to `Lifted.Exit`.-* [#16](https://github.com/kowainik/relude/issues/16):+- [#16](https://github.com/kowainik/relude/issues/16): Rename `whenLeft`, `whenRight`, `whenLeftM`, `whenRightM` to `whenLeft_` and `whenRight_`, `whenLeftM_` and `whenRightM_`. Add `whenLeft`, `whenRight`, `whenLeftM`, `whenRightM` which return the value.-* [#18](https://github.com/kowainik/relude/issues/18):+- [#18](https://github.com/kowainik/relude/issues/18): Add `LazyStrict` type class for conversions.-* `map` is not `fmap` anymore. Reexport `map` from `Data.List`-* [#12](https://github.com/kowainik/relude/issues/12):+- `map` is not `fmap` anymore. Reexport `map` from `Data.List`+- [#12](https://github.com/kowainik/relude/issues/12): Remove `liquid-haskell` support.-* [#20](https://github.com/kowainik/relude/issues/20):+- [#20](https://github.com/kowainik/relude/issues/20): Add `viaNonEmpty` function.-* [#21](https://github.com/kowainik/relude/issues/21):+- [#21](https://github.com/kowainik/relude/issues/21): Add `MonadFail` instance for `Either`.-* [#17](https://github.com/kowainik/relude/issues/17):+- [#17](https://github.com/kowainik/relude/issues/17): Add `foldMapA` and `foldMapM` functions.-* [#4](https://github.com/kowainik/relude/issues/4):+- [#4](https://github.com/kowainik/relude/issues/4): Rename package to `Relude`.-* [#14](https://github.com/kowainik/relude/issues/14):+- [#14](https://github.com/kowainik/relude/issues/14): Add `Relude.Extra.*` modules which are not exported by default but have useful functions.-* [#8](https://github.com/kowainik/relude/issues/8):+- [#8](https://github.com/kowainik/relude/issues/8): Introduce `StaticMap` and `DynamicMap` type classes as universal interface for Map-like structures.
README.md view
@@ -11,7 +11,7 @@ **`relude`** is a safe, performant, user-friendly and lightweight Haskell standard library. -The default `Prelude` is not perfect and doesn't always satisfies one's needs.+The default `Prelude` is not perfect and doesn't always satisfy one's needs. At this stage you may want to try an alternative prelude library. In this README we are going to give you convincing reasons to consider using `relude` as such alternative in your next project.@@ -32,33 +32,34 @@ `relude` strives to encourage best-practices and reduce the chances of introducing a bug. - | __Partial__ | __Total__ |- |---------------------------------|--------------------------------------------|- | `head :: [a] -> a` | `head :: NonEmpty a -> a` |- | `tail :: [a] -> [a]` | `tail :: NonEmpty a -> [a]` |- | `read :: Read a => String -> a` | `readMaybe :: Read a => String -> Maybe a` |- | `fromJust :: Maybe a -> a` | `fromMaybe :: a -> Maybe a -> a` |+| **Partial** | **Total** |+| ------------------------------- | ------------------------------------------ |+| `head :: [a] -> a` | `head :: NonEmpty a -> a` |+| `tail :: [a] -> [a]` | `tail :: NonEmpty a -> [a]` |+| `read :: Read a => String -> a` | `readMaybe :: Read a => String -> Maybe a` |+| `fromJust :: Maybe a -> a` | `fromMaybe :: a -> Maybe a -> a` | -3. **Type-safety**. We use the *"make invalid states unrepresentable"* motto as one+3. **Type-safety**. We use the _"make invalid states unrepresentable"_ motto as one of our guiding principles. If it is possible, we express this concept through the types. - _Example:_ Here the function's name type and actions are aligned with each other+ _Example:_ Here the function's name type and actions are aligned with each other - ```haskell- whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f ()- ```- While in here, the type could represent an unreachable state:+ ```haskell+ whenNotNull :: Applicative f => [a] -> (NonEmpty a -> f ()) -> f ()+ ``` - ```haskell- whenNotNull :: Applicative f => [a] -> ([a] -> f ()) -> f ()- ```+ While in here, the type could represent an unreachable state: + ```haskell+ whenNotNull :: Applicative f => [a] -> ([a] -> f ()) -> f ()+ ```+ 4. **Performance.** We prefer `Text` over [`String`](https://www.reddit.com/r/haskell/comments/29jw0s/whats_wrong_with_string/), use space-leaks-free functions (e.g. our custom performant `sum` and `product`), introduce `{-# INLINE #-}` and `{-# SPECIALIZE #-}` pragmas where appropriate, and make efficient container types- (e.g. `Map`, `HashMap`, `Set`) more accesible.+ (e.g. `Map`, `HashMap`, `Set`) more accessible. 5. **Minimalism** (low number of dependencies). We do not force users of `relude` to stick to any specific lens or text formatting or logging@@ -70,20 +71,21 @@ types and functions into scope, and make available functions easier to use. Some examples of conveniences: - + No need to add `containers`, `unordered-containers`, `text` and+ - No need to add `containers`, `unordered-containers`, `text` and `bytestring` to dependencies in your `.cabal` file to use the main API of these libraries- + No need to import types like `NonEmpty`, `Text`, `Set`, `Reader[T]`, `MVar`, `STM`- + Functions like `liftIO`, `fromMaybe`, `sortWith` are avaiable by default as well- + `IO` actions are lifted to `MonadIO`+ - No need to import types like `NonEmpty`, `Text`, `Set`, `Reader[T]`, `MVar`, `STM`+ - Functions like `liftIO`, `fromMaybe`, `sortWith` are available by default as well+ - `IO` actions are lifted to `MonadIO` 7. **Excellent documentation.**- + Tutorial- + Migration guide from `Prelude`- + Haddock for every function with examples tested by++ - Tutorial+ - Migration guide from `Prelude`+ - Haddock for every function with examples tested by [`doctest`](http://hackage.haskell.org/package/doctest)- + Documentation on [internal module structure](http://hackage.haskell.org/package/relude/docs/Relude.html)- + `relude`-specific [HLint](http://hackage.haskell.org/package/hlint) rules:+ - Documentation on [internal module structure](http://hackage.haskell.org/package/relude/docs/Relude.html)+ - `relude`-specific [HLint](http://hackage.haskell.org/package/hlint) rules: [`.hlint.yaml`](https://github.com/kowainik/relude/blob/main/.hlint.yaml) 8. **User-friendliness.** Anyone should be able to quickly migrate to `relude`. Only@@ -115,23 +117,28 @@ blog post by [Type Classes](https://typeclasses.com/) that highlights `relude`. -* [No implicit Prelude](https://typeclasses.com/ghc/no-implicit-prelude)+- [No implicit Prelude](https://typeclasses.com/ghc/no-implicit-prelude) +For guiding development principles behind `relude` and comparison with+`base`, check out the following talk:++- [](https://www.youtube.com/watch?v=qwAmiJ5M_zM)+ ## Structure of this tutorial This tutorial has several parts: 1. [When to use an alternative prelude?](#when-to-use-an-alternative-prelude) 2. [Get started](#get-started)- * [Mixins](#mixins)- * [base-noprelude](#base-noprelude)- * [NoImplicitPrelude](#NoImplicitPrelude)+ - [Mixins](#mixins)+ - [NoImplicitPrelude](#noimplicitprelude)+ - [base-noprelude (not recommended)](#base-noprelude) 3. [Difference from Prelude](#difference-from-prelude) 4. [Reexports](#reexports) 5. [What's new?](#whats-new) 6. [Migration guide](#migration-guide) 7. [Comparison with other alternative preludes](#comparison-with-other-alternative-preludes)- * [Relude vs Protolude](#relude-vs-protolude)+ - [Relude vs Protolude](#relude-vs-protolude) 8. [For developers](#for-developers) This is neither a tutorial on _Haskell Standard Library_ nor a tutorial on each@@ -152,13 +159,13 @@ Replacing default `Prelude` from `base` has the following _disadvantages_: -1. Increased entry threshold: you need to *learn* a different standard library.- + `relude` tries to lower this threshold as much as possible: it comes with- the excellent documentation, no custom abstractions, and behavior is- changed only for a small subset of functions.+1. Increased entry threshold: you need to _learn_ a different standard library.+ - `relude` tries to lower this threshold as much as possible: it comes with+ the excellent documentation, no custom abstractions, and behavior is+ changed only for a small subset of functions. 2. Extra dependencies: adding more libraries to dependencies increases build times and maintenance burden.- + `relude` depends only on the boot libraries (almost) which results in small+ - `relude` depends only on the boot libraries (almost) which results in small build time, follows [PVP](https://pvp.haskell.org/) and cares about backwards compatibility. @@ -226,8 +233,8 @@ library exposed-modules: Example- build-depends: base >= 4.10 && < 4.13- , relude ^>= 1.0.0.0+ build-depends: base >= 4.14 && < 4.17+ , relude ^>= 1.1.0.0 mixins: base hiding (Prelude) , relude (Relude as Prelude)@@ -274,10 +281,40 @@ > If having `stack repl` crucial for your workflow, see the following options of > how to use Relude in your project. +### NoImplicitPrelude++[[Back to the Table of Contents] ↑](#structure-of-this-tutorial)++For this option, you need to disable the default `Prelude` module first.+To disable the built-in prelude on module basis, you can add the following+pragma at the top of your file:++```haskell+{-# LANGUAGE NoImplicitPrelude #-}+```++if you want to disable the default `Prelude` for every module by default, you+can specify this directly in your project `.cabal` file:++```haskell+default-extensions: NoImplicitPrelude+```++Then you need to add `relude` as a dependency of your project.++After doing all above, you can now use `Relude` in any module of your project by+adding a single import:++```haskell+import Relude+```+ ### base-noprelude [[Back to the Table of Contents] ↑](#structure-of-this-tutorial) +:warning: _This strategy is not reccommended. The package `base-noprelude` is currently not being maintained and its use is likely to cause issues with newer versions of ghc and libraries._+ Alternatively, you can use the `base-noprelude` trick to enable alternative preludes. This approach can be helpful if you want to have your own `Prelude` module with some custom functions, not provided by@@ -288,6 +325,7 @@ 2. Add the `relude` dependency to your `.cabal` file. 3. Create the file called `Prelude.hs` in your source directory with the following content:+ ```haskell module Prelude ( module Relude@@ -295,6 +333,7 @@ import Relude ```+ 4. Add this module to `exposed-modules` in your `.cabal` file: ```cabal exposed-modules: Prelude@@ -308,59 +347,31 @@ you don't need to import module manually inside each file and enable the `NoImplicitPrelude` extension. -### NoImplicitPrelude--[[Back to the Table of Contents] ↑](#structure-of-this-tutorial)--For this option, you need to disable the default `Prelude` module first.-To disable the built-in prelude on module basis, you can add the following-pragma at the top of your file:--```haskell-{-# LANGUAGE NoImplicitPrelude #-}-```--if you want to disable the default `Prelude` for every module by default, you-can specify this directly in your project `.cabal` file:--```haskell-default-extensions: NoImplicitPrelude-```--Then you need to add `relude` as a dependency of your project.--After doing all above, you can now use `Relude` in any module of your project by-adding a single import:--```haskell-import Relude-```- ## Difference from Prelude [[Back to the Table of Contents] ↑](#structure-of-this-tutorial) Main differences from `Prelude` can be grouped into the following categories: -* Changed behavior of common functions- + `head`, `tail`, `last`, `init` work with `NonEmpty a` instead of `[a]`.+- Changed behavior of common functions+ - `head`, `tail`, `last`, `init` work with `NonEmpty a` instead of `[a]`. * `lines`, `unlines`, `words`, `unwords` work with `Text` instead of `String`.- + `show` is polymorphic over the return type.- + Functions `sum` and `product` are strict now, which makes them more efficient.- + You can't call `elem` and `notElem` functions over `Set` and `HashSet`.+ - `show` is polymorphic over the return type.+ - Functions `sum` and `product` are strict now, which makes them more efficient.+ - You can't call `elem` and `notElem` functions over `Set` and `HashSet`. These functions are forbidden for these two types due to performance reasons.- + `error` takes `Text`.- + `undefined` triggers a compiler warning, because you probably don't want to+ - `error` takes `Text`.+ - `undefined` triggers a compiler warning, because you probably don't want to leave `undefined` in your code. Either use `throwIO`, `Except`, `error` or `bug`.-* Not reexported- + `read`- + `lookup` for lists- + `log`-* Completely new functions are brought into scope- + See the [What's new?](#whats-new) section for a detailed overview.-* New reexports- + See the [Reexports](#reexports) section for a detailed overview.+- Not reexported+ - `read`+ - `lookup` for lists+ - `log`+- Completely new functions are brought into scope+ - See the [What's new?](#whats-new) section for a detailed overview.+- New reexports+ - See the [Reexports](#reexports) section for a detailed overview. ## Reexports @@ -368,17 +379,17 @@ `relude` reexports some parts of the following libraries: -* [`base`](http://hackage.haskell.org/package/base)-* [`bytestring`](http://hackage.haskell.org/package/bytestring)-* [`containers`](http://hackage.haskell.org/package/containers)-* [`deepseq`](http://hackage.haskell.org/package/deepseq)-* [`ghc-prim`](http://hackage.haskell.org/package/ghc-prim)-* [`hashable`](http://hackage.haskell.org/package/hashable)-* [`mtl`](http://hackage.haskell.org/package/mtl)-* [`stm`](http://hackage.haskell.org/package/stm)-* [`text`](http://hackage.haskell.org/package/text)-* [`transformers`](http://hackage.haskell.org/package/transformers)-* [`unordered-containers`](http://hackage.haskell.org/package/unordered-containers)+- [`base`](http://hackage.haskell.org/package/base)+- [`bytestring`](http://hackage.haskell.org/package/bytestring)+- [`containers`](http://hackage.haskell.org/package/containers)+- [`deepseq`](http://hackage.haskell.org/package/deepseq)+- [`ghc-prim`](http://hackage.haskell.org/package/ghc-prim)+- [`hashable`](http://hackage.haskell.org/package/hashable)+- [`mtl`](http://hackage.haskell.org/package/mtl)+- [`stm`](http://hackage.haskell.org/package/stm)+- [`text`](http://hackage.haskell.org/package/text)+- [`transformers`](http://hackage.haskell.org/package/transformers)+- [`unordered-containers`](http://hackage.haskell.org/package/unordered-containers) If you want to clean up your imports after switching to `relude`, you can use the `relude`-specific@@ -390,14 +401,14 @@ Multiple sorting functions are available for different use-cases: - + `sortBy :: (a -> a -> Ordering) -> [a] -> [a]`: sorts a list using given- custom comparator.- + `sortWith :: Ord b => (a -> b) -> [a] -> [a]`: sorts a list based on some- property of its elements.- + `sortOn :: Ord b => (a -> b) -> [a] -> [a]`: similar to `sortWith`, but more- time-efficient if function is calculated slowly (though less- space-efficient). So you should write `sortOn length` (would sort elements- by length) but `sortWith fst` (would sort list of pairs by first element).+- `sortBy :: (a -> a -> Ordering) -> [a] -> [a]`: sorts a list using given+ custom comparator.+- `sortWith :: Ord b => (a -> b) -> [a] -> [a]`: sorts a list based on some+ property of its elements.+- `sortOn :: Ord b => (a -> b) -> [a] -> [a]`: similar to `sortWith`, but more+ time-efficient if function is calculated slowly (though less+ space-efficient). So you should write `sortOn length` (would sort elements+ by length) but `sortWith fst` (would sort list of pairs by first element). `readMaybe` and `readEither` are similar to `read` but unlike it, they are total and return either `Maybe` or `Either` with a parse error.@@ -405,9 +416,9 @@ `(&)` is the reverse application. The following three expressions are semantically equivalent: -* `g (f x)`-* `g $ f $ x`-* `x & f & g`+- `g (f x)`+- `g $ f $ x`+- `x & f & g` Some generally useful modules from `base` package are exported, e.g. `Control.Applicative`, `Data.Traversable`, `Data.Monoid`, `Data.List`,@@ -419,10 +430,10 @@ [`Bifunctor`](http://hackage.haskell.org/package/base/docs/Data-Bifunctor.html) type class with useful instances is exported. -* `first` and `second` functions apply a function to the first and+- `first` and `second` functions apply a function to the first and second part of a `Bifunctor` (`fst` and `snd` for tuples, `Left` and `Right` for `Either`).-* `bimap` takes two functions and applies them to the first and second parts respectively.+- `bimap` takes two functions and applies them to the first and second parts respectively. `trace`, `traceM`, `traceShow`, etc. are available by default. However, GHC will warn you if you accidentally leave them in code. Same goes for the `undefined`@@ -442,9 +453,9 @@ The following types from these two packages are exported: -* Maps: strict versions of `Map`, `HashMap`, `IntMap`.-* Sets: `Set`, `HashSet`, `IntSet`.-* Sequences: `Seq`.+- Maps: strict versions of `Map`, `HashMap`, `IntMap`.+- Sets: `Set`, `HashSet`, `IntSet`.+- Sequences: `Seq`. ### text & bytestring @@ -468,8 +479,8 @@ The following parts of these two libraries are exported: -* Transformers: `State[T]`, `Reader[T]`, `ExceptT`, `MaybeT`.-* Classes: `MonadReader`, `MonadState`.+- Transformers: `State[T]`, `Reader[T]`, `ExceptT`, `MaybeT`.+- Classes: `MonadReader`, `MonadState`. ### Deepseq @@ -488,7 +499,8 @@ ### Available by default -* Safe analogue for the list functions:+- Safe analogue for the list functions:+ ```haskell head :: NonEmpty a -> a -- the first element of the list tail :: NonEmpty a -> [a] -- the list without the first element@@ -507,18 +519,18 @@ Nothing ``` -* `uncons` splits a list at the first element.-* `ordNub` and `sortNub` are _O(n log n)_ versions of `nub` (which is quadratic),+- `uncons` splits a list at the first element.+- `ordNub` and `sortNub` are _O(n log n)_ versions of `nub` (which is quadratic), also, `hashNub` and `unstableNub` are almost _O(n)_ versions of `nub`, and `intNub` for fast `Int`s nub.-* `whenM`, `unlessM`, `ifM`, `guardM` — monadic guard combinators, that work+- `whenM`, `unlessM`, `ifM`, `guardM` — monadic guard combinators, that work with any `Monad`, e.g. `whenM (doesFileExist "foo")`.-* General fold functions:+- General fold functions: ```haskell foldMapA :: (Monoid b, Applicative m, Foldable f) => (a -> m b) -> f a -> m b foldMapM :: (Monoid b, Monad m, Foldable f) => (a -> m b) -> f a -> m b ```-* `when(Just|Nothing|Left|Right|NotEmpty)[M][_]` functions that+- `when(Just|Nothing|Left|Right|NotEmpty)[M][_]` functions that let you conditionally execute something. **Before:**@@ -536,23 +548,23 @@ f x ``` -* `for_` and `forM_` for loops.+- `for_` and `forM_` for loops. ```haskell for_ files $ \file -> do ... ``` -* `andM`, `allM`, `anyM`, `orM` are monadic versions of the corresponding+- `andM`, `allM`, `anyM`, `orM` are monadic versions of the corresponding functions from `base`.-* Conversions between `Either` and `Maybe`, e.g. `rightToMaybe` and `maybeToLeft`+- Conversions between `Either` and `Maybe`, e.g. `rightToMaybe` and `maybeToLeft` with clear semantics.-* `using(Reader|State)[T]` functions as aliases for `flip run(Reader|State)[T]`.-* [`One` type class](http://hackage.haskell.org/package/relude/docs/Relude-Container-One.html)+- `using(Reader|State)[T]` functions as aliases for `flip run(Reader|State)[T]`.+- [`One` type class](http://hackage.haskell.org/package/relude/docs/Relude-Container-One.html) for creating singleton containers (even monomorphic ones like `Text`).-* `evaluateWHNF` and `evaluateNF` functions as clearer and lifted aliases for+- `evaluateWHNF` and `evaluateNF` functions as clearer and lifted aliases for `evaluate` and `evaluate . force`.-* `MonadFail` instance for `Either`.+- `MonadFail` instance for `Either`. ### Extra bonuses @@ -562,13 +574,15 @@ These extra modules include the following functionality: -* Convenient functions to work with `(Bounded a, Enum a)` types:+- Convenient functions to work with `(Bounded a, Enum a)` types:+ 1. `universe :: (Bounded a, Enum a) => [a]`: get all values of the type. ```haskell ghci> universe @Bool [True,False] ```+ 2. `inverseMap :: (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a`: convert functions like `show` to parsers: @@ -577,7 +591,7 @@ readMyEnums = inverseMap myShow ``` -* Nice helpers to deal with `newtype`s in a more pleasant way:+- Nice helpers to deal with `newtype`s in a more pleasant way: ```haskell ghci> newtype Foo = Foo Bool deriving Show@@ -585,7 +599,7 @@ Foo False ``` -* Functions to operate with `CallStack`:+- Functions to operate with `CallStack`: ```haskell ghci> foo :: HasCallStack => String; foo = ownName@@ -593,11 +607,11 @@ "foo" ``` -* `Foldable1` typeclass that contains generalized interface for folding+- `Foldable1` typeclass that contains generalized interface for folding non-empty structures like `NonEmpty`.-* [`StaticMap` and `DynamicMap` type classes](src/Relude/Extra/Map.hs) as a+- [`StaticMap` and `DynamicMap` type classes](https://github.com/kowainik/relude/blob/main/src/Relude/Extra/Map.hs) as a general interface for `Map`-like data structures.-* And much more!+- And much more! Explore `Extra` modules: [`Relude.Extra`](http://hackage.haskell.org/package/relude/docs/Relude-Extra.html) @@ -609,7 +623,7 @@ to the `relude` library. In order to replace the default `Prelude` with `relude` you should start with-instructions provided in the [_Get Started_](#get-started) section.+instructions provided in the [_Get Started_](#get-started) section. ### Code changes @@ -621,50 +635,52 @@ 1. Change `[a]` to `NonEmpty a` where it makes sense. 2. Use functions which return `Maybe`. There is the `viaNonEmpty` function for this. And you can use it like `viaNonEmpty last l`.- + `tail` is `drop 1`. It's almost never a good idea to use `tail` from `Prelude`.+ - `tail` is `drop 1`. It's almost never a good idea to use `tail` from `Prelude`. 3. Add `import qualified Relude.Unsafe as Unsafe` and replace the function with its qualified usage: `Unsafe.head`. 3. If you use `fromJust` or `!!` you should import them from `import qualified Relude.Unsafe as Unsafe`. 4. If you use `foldr` or `forM_` or similar for something like `Maybe a` or `Either a b` it is recommended to replace usages of such functions with the monomorhpic alternatives:- * `Maybe`- + `(?:) :: Maybe a -> a -> a`- + `fromMaybe :: a -> Maybe a -> a`- + `maybeToList :: Maybe a -> [a]`- + `maybeToMonoid :: Monoid m => Maybe m -> m`- + `maybe :: b -> (a -> b) -> Maybe a -> b`- + `whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()`- + `whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()` - * `Either`- + `fromLeft :: a -> Either a b -> a`- + `fromRight :: b -> Either a b -> b`- + `either :: (a -> c) -> (b -> c) -> Either a b -> c`- + `whenRight_ :: Applicative f => Either l r -> (r -> f ()) -> f ()`- + `whenRightM_ :: Monad m => m (Either l r) -> (r -> m ()) -> m ()`+ - `Maybe` + - `(?:) :: Maybe a -> a -> a`+ - `fromMaybe :: a -> Maybe a -> a`+ - `maybeToList :: Maybe a -> [a]`+ - `maybeToMonoid :: Monoid m => Maybe m -> m`+ - `maybe :: b -> (a -> b) -> Maybe a -> b`+ - `whenJust :: Applicative f => Maybe a -> (a -> f ()) -> f ()`+ - `whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()`++ - `Either`+ - `fromLeft :: a -> Either a b -> a`+ - `fromRight :: b -> Either a b -> b`+ - `either :: (a -> c) -> (b -> c) -> Either a b -> c`+ - `whenRight_ :: Applicative f => Either l r -> (r -> f ()) -> f ()`+ - `whenRightM_ :: Monad m => m (Either l r) -> (r -> m ()) -> m ()`+ 5. Replace the `String` type with more efficient and suitable ones (e.g. `Text`):- + Replace `(++)` with `(<>)` for `String`-like types.- + Use `toText/toLText/toString` functions to convert to `Text/LazyText/String` types.- + Use `encodeUtf8/decodeUtf8` to convert to/from `ByteString`.- + Use `(putStr[Ln]|readFile|writeFile|appendFile)[Text|LText|BS|LBS]` functions. -6. Since `show` doesn't come from `Show` anymore, you need to export- `Text.Show` module if you want to implement `Show` instance manually. This can be done in the following way:+ - Replace `(++)` with `(<>)` for `String`-like types.+ - Use `toText/toLText/toString` functions to convert to `Text/LazyText/String` types.+ - Use `encodeUtf8/decodeUtf8` to convert to/from `ByteString`.+ - Use `(putStr[Ln]|readFile|writeFile|appendFile)[Text|LText|BS|LBS]` functions. - ```haskell- import qualified Text.Show+6. Since `show` doesn't come from `Show` anymore, you need to import the+ `Text.Show` module if you want to implement `Show` instance manually. This can be done in the following way: - data MyType = ...+```haskell+import qualified Text.Show - instance Show MyType where- show :: MyType -> String- show = ...- ```+data MyType = ... -7. Run `hlint` using `.hlint.yaml` file from `relude` package to cleanup code and imports.+instance Show MyType where+ show :: MyType -> String+ show = ...+``` +7. Run `hlint` using `.hlint.yaml` file from `relude` package to cleanup code and imports. ### Running HLint on CI @@ -681,14 +697,14 @@ two commands on your CI: ```yaml-curl https://raw.githubusercontent.com/kowainik/relude/v1.0.0.0/.hlint.yaml -o .hlint-relude.yaml+curl https://raw.githubusercontent.com/kowainik/relude/v1.1.0.0/.hlint.yaml -o .hlint-relude.yaml curl -sSL https://raw.github.com/ndmitchell/neil/master/misc/travis.sh | sh -s -- hlint -h .hlint-relude.yaml . ``` See an example of this feature described in the following blog post about Travis CI settings: -* [Kodimensional: Dead simple Haskell Travis settings for cabal and stack](https://kodimensional.dev/posts/2019-02-25-haskell-travis#customization-hlint)+- [Kodimensional: Dead simple Haskell Travis settings for cabal and stack](https://kodimensional.dev/posts/2019-02-25-haskell-travis#customization-hlint) ## Comparison with other alternative preludes @@ -718,20 +734,20 @@ _O(n)_ time and you can accidentally use `elem` from `Foldable` but with `relude` you can't). 4. Protolude supports older GHC versions (from GHC 7.6.1) while `relude` only- supports from GHC 8.2.2. So if you aim ancient GHC versions, `protolude`+ supports from GHC 8.4. So if you aim ancient GHC versions, `protolude` might be a better choice. But because of that it contains a lot of CPP, code is scary in some places as a consequence and it is more difficult to add, remove or change things there. 5. `relude` has much better documentation:- * [High-level overview of internal module structure](http://hackage.haskell.org/package/relude/docs/Relude.html)- * 100% Haddock coverage- * Every function has usage examples and all examples are tested with- `doctest` (which also sometimes hard to do due to the multiple GHC- versions support, but we try really hard)- * [Tutorial + migration guide](#structure-of-this-tutorial) from- `Prelude` and just general description of the whole package and libraries- it depends on.-6. `relude` has less dependencies and is slightly lighter because of that but still+ - [High-level overview of internal module structure](http://hackage.haskell.org/package/relude/docs/Relude.html)+ - 100% Haddock coverage+ - Every function has usage examples and all examples are tested with+ `doctest` (which also sometimes hard to do due to the multiple GHC+ versions support, but we try really hard)+ - [Tutorial + migration guide](#structure-of-this-tutorial) from+ `Prelude` and just general description of the whole package and libraries+ it depends on.+6. `relude` has fewer dependencies and is slightly lighter because of that but still is very powerful and useful. 7. `relude` is opt-in oriented and has a notion of `Extra.*` modules that are not exported by default from the `Relude` module. That means that we do not@@ -749,17 +765,15 @@ Note, that we are using custom `hlint` setting which are `Relude` specific. To keep it up to date don't forget to reflect your changes in this file. We are-using `Dhall` to maintain the configurations. To use it follow the steps below.+using `Dhall` to maintain the configurations (lang version 22.0.0). To+use it follow the steps below. First time: ```shell-$ cabal v2-install dhall-yaml+$ cabal v2-install dhall-yaml-1.2.10 ``` -Dhall 16.0.0 is required, so make sure that the previous command installed-`dhall-yaml` >= 1.2.5.- To generate `hlint` file: ```shell@@ -774,7 +788,7 @@ See our blog post where we describe the details of the implementation for this solution: -* [Dhall To HLint](https://kowainik.github.io/posts/2018-09-09-dhall-to-hlint)+- [Dhall To HLint](https://kowainik.github.io/posts/2018-09-09-dhall-to-hlint) ### Producing dependency graph @@ -790,4 +804,14 @@ ```shell cabal-plan dot --root lib:relude | dot -Tpng -o relude-dependency-graph.png+```++### Updating license headers++Install the `headroom` tool and run it from this repository:++```shell+cabal v2-install headroom-0.4.3.0+headroom run+rg "SPDX-License-Identifier : MPL-2.0" --files-with-matches src/ | xargs sed -i 's/SPDX-License-Identifier : MPL-2.0/SPDX-License-Identifier : MIT/g' ```
benchmark/Main.hs view
@@ -5,8 +5,7 @@ import Relude hiding (show) import Data.List (nub)-import Criterion (Benchmark, bench, bgroup, nf)-import Criterion.Main (defaultMain)+import Test.Tasty.Bench (Benchmark, bench, bgroup, defaultMain, nf) import Prelude (show) import qualified Data.HashSet as HashSet (insert)
relude.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: relude-version: 1.0.0.1+version: 1.2.2.2 synopsis: Safe, performant, user-friendly and lightweight Haskell Standard Library description: @__relude__@ is an alternative prelude library. If you find the default@@ -41,7 +41,7 @@ use space-leaks-free functions (e.g. our custom performant @sum@ and @product@), introduce @\{\-\# INLINE \#\-\}@ and @\{\-\# SPECIALIZE \#\-\}@ pragmas where appropriate, and make efficient container types- (e.g. @Map@, @HashMap@, @Set@) more accesible.+ (e.g. @Map@, @HashMap@, @Set@) more accessible. * __Minimalism__ (low number of dependencies). We do not force users of @relude@ to stick to any specific lens or text formatting or logging@@ -57,7 +57,7 @@ and @bytestring@ to dependencies in your @.cabal@ file to use the main API of these libraries 2. No need to import types like @NonEmpty@, @Text@, @Set@, @Reader[T]@, @MVar@, @STM@- 3. Functions like @liftIO@, @fromMaybe@, @sortWith@ are avaiable by default as well+ 3. Functions like @liftIO@, @fromMaybe@, @sortWith@ are available by default as well 4. @IO@ actions are lifted to @MonadIO@ * __Excellent documentation.__@@ -85,18 +85,22 @@ license-file: LICENSE author: Dmitrii Kovanikov, Veronika Romashkina, Stephen Diehl, Serokell maintainer: Kowainik <xrom.xkov@gmail.com>-copyright: 2016 Stephen Diehl, 2016-2018 Serokell, 2018-2021 Kowainik+copyright: 2016 Stephen Diehl, 2016-2018 Serokell, 2018-2023 Kowainik category: Prelude stability: stable build-type: Simple extra-doc-files: CHANGELOG.md README.md-tested-with: GHC == 8.2.2- GHC == 8.4.4+tested-with: GHC == 8.4.4 GHC == 8.6.5 GHC == 8.8.4- GHC == 8.10.4- GHC == 9.0.1+ GHC == 8.10.7+ GHC == 9.0.2+ GHC == 9.2.8+ GHC == 9.4.7+ GHC == 9.6.6+ GHC == 9.8.2+ GHC == 9.10.1 source-repository head@@ -104,8 +108,6 @@ location: git@github.com:kowainik/relude.git common common-options- build-depends: base >= 4.10 && < 4.16- ghc-options: -Wall -Wcompat -Widentities@@ -121,6 +123,18 @@ ghc-options: -Wmissing-deriving-strategies if impl(ghc >= 8.10) ghc-options: -Wunused-packages+ if impl(ghc >= 9.0)+ ghc-options: -Winvalid-haddock+ if impl(ghc >= 9.2)+ ghc-options: -Wredundant-bang-patterns+ -Woperator-whitespace+ if impl(ghc >= 9.4 && < 9.10)+ ghc-options: -Wforall-identifier+ if impl(ghc >= 9.4)+ ghc-options: -Wredundant-strictness-flags+ if impl(ghc >= 9.8)+ ghc-options: -Wterm-variable-capture+ -Winconsistent-flags default-language: Haskell2010@@ -221,15 +235,16 @@ , Data.ByteString.Short - build-depends: bytestring >= 0.10 && < 0.12- , containers >= 0.5.7 && < 0.7- , deepseq ^>= 1.4- , ghc-prim >= 0.4.0.0 && < 0.8- , hashable >= 1.2 && < 1.4- , mtl ^>= 2.2+ build-depends: base >= 4.11 && < 4.22+ , bytestring >= 0.10 && < 0.13+ , containers >= 0.5.10 && < 0.9+ , deepseq >= 1.4 && < 1.6+ , ghc-prim >= 0.5.0.0 && < 0.14+ , hashable >= 1.2 && < 1.6+ , mtl >= 2.2 && < 2.4 , stm >= 2.4 && < 2.6- , text ^>= 1.2- , transformers ^>= 0.5+ , text >= 1.2 && < 2.2+ , transformers >= 0.5 && < 0.7 , unordered-containers >= 0.2.7 && < 0.3 @@ -242,11 +257,12 @@ other-modules: Test.Relude.Gen Test.Relude.Container.One Test.Relude.Property- build-depends: relude+ build-depends: base+ , relude , bytestring , containers , text- , hedgehog ^>= 1.0+ , hedgehog >= 1.0 && < 1.6 ghc-options: -threaded @@ -257,7 +273,7 @@ main-is: Doctest.hs build-depends: relude- , doctest+ , doctest >= 0.20 && < 0.25 , Glob ghc-options: -threaded@@ -268,10 +284,9 @@ hs-source-dirs: benchmark main-is: Main.hs - build-depends: relude- , criterion+ build-depends: base+ , relude+ , tasty-bench , unordered-containers - ghc-options: -threaded- -rtsopts- -with-rtsopts=-N+ ghc-options: -rtsopts
src/Relude.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable @relude@ is a safe, performant, user-friendly and lightweight Haskell standard library.@@ -262,7 +263,7 @@ | __"Relude.Extra.Foldable"__ | Extra folds for instances of the 'Foldable' typeclass. | | | Currently, just a short-circuitable left fold. | +------------------------------+-----------------------------------------------------------+-| __"Relude.Extra.Foldable1"__ | 'Relude.Extra.Foldable1.Foldable1' typeclass |+| __"Relude.Extra.Foldable1"__ | t'Relude.Extra.Foldable1.Foldable1' typeclass | | | like 'Foldable' but for non-empty structures. | +------------------------------+-----------------------------------------------------------+ | __"Relude.Extra.Group"__ | Grouping functions, polymorphic on return @Map@ type. |
src/Relude/Applicative.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Applicative+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module contains reexports of 'Applicative' and related functional. Additionally, it provides convenient combinators to work with 'Applicative'.
src/Relude/Base.hs view
@@ -1,13 +1,16 @@-{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE ExplicitNamespaces #-}+{-# LANGUAGE Trustworthy #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Base+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports from @Data.*@ and @GHC.*@ modules of <https://hackage.haskell.org/package/base base> package.@@ -28,6 +31,9 @@ , module Data.Coerce , module Data.Kind , module Data.Proxy+#if __GLASGOW_HASKELL__ >= 904+ , module Data.Type.Equality+#endif , module Data.Typeable , module Data.Void @@ -50,13 +56,16 @@ import System.IO (FilePath, IO, IOMode (..)) -- Base typeclasses-import Data.Eq (Eq (..))+import Data.Eq (Eq, (/=), (==)) import Data.Ord (Down (..), Ord (..), Ordering (..), comparing) -- Types for type-level computation import Data.Coerce (Coercible, coerce) import Data.Kind (Constraint, Type) import Data.Proxy (Proxy (..))+#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import Data.Typeable (Typeable) import Data.Void (Void, absurd, vacuous)
src/Relude/Bool.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Bool+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Convenient commonly used and very helpful functions to work with 'Bool' and also with monads.
src/Relude/Bool/Guard.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Bool.Guard+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Monadic boolean combinators. -}
src/Relude/Bool/Reexport.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Bool.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports functions to work with 'Bool' type. -}
src/Relude/Container.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Container+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module exports all container-related stuff. -}
src/Relude/Container/One.hs view
@@ -4,20 +4,22 @@ {-# LANGUAGE TypeFamilies #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Container.One+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable 'One' is a typeclass for creating structures from a singleton element. It has three main goals: 1. Give a shorter name for the construction: uses 'one' instead of common @singleton@. 2. Work with monomorphic structures like 'T.Text' or 'IntSet'.-3. Give a clearer and less scary name for cases where you can use 'Relude.pure' or @(:[])@.+3. Give a clearer and less scary name for cases where you can use 'Relude.Applicative.pure'+ or @(:[])@. @since 0.1.0 -}@@ -78,13 +80,13 @@ -- Lists {- | Allows to create a singleton list. You might prefer function with name 'one'-instead of 'Relude.pure' or @(:[])@.+instead of 'Relude.Applicative.pure' or @(:[])@. >>> one 42 :: [Int] [42] @-law> 'Relude.length' ('one' @[a] x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @[a] x) ≡ 1 @ -} instance One [a] where@@ -95,13 +97,13 @@ {-# INLINE one #-} {- | Allows to create singleton 'NE.NonEmpty' list. You might prefer function with-name 'one' instead of 'Relude.pure' or @(:|[])@.+name 'one' instead of 'Relude.Applicative.pure' or @(:|[])@. >>> one 42 :: NonEmpty Int 42 :| [] @-law> 'Relude.length' ('one' @('NE.NonEmpty' a) x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('NE.NonEmpty' a) x) ≡ 1 @ -} instance One (NE.NonEmpty a) where@@ -117,7 +119,7 @@ fromList [42] @-law> 'Relude.length' ('one' @('SEQ.Seq' a) x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('SEQ.Seq' a) x) ≡ 1 @ -} instance One (SEQ.Seq a) where@@ -217,7 +219,7 @@ fromList [(3,"foo")] @-law> 'Relude.length' ('one' @('Map' k v) (k, v)) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('Map' k v) (k, v)) ≡ 1 @ -} instance One (Map k v) where@@ -233,7 +235,7 @@ fromList [(3,"foo")] @-law> 'Relude.length' ('one' @('HashMap' k v) (k, v)) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('HashMap' k v) (k, v)) ≡ 1 @ -} instance Hashable k => One (HashMap k v) where@@ -249,7 +251,7 @@ fromList [(3,"foo")] @-law> 'Relude.length' ('one' @('IntMap' a) x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('IntMap' a) x) ≡ 1 @ -} instance One (IntMap v) where@@ -267,7 +269,7 @@ fromList [42] @-law> 'Relude.length' ('one' @('Set' a) x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('Set' a) x) ≡ 1 @ -} instance One (Set a) where@@ -283,7 +285,7 @@ fromList [42] @-law> 'Relude.length' ('one' @('HashSet' a) x) ≡ 1+law> 'Relude.Foldable.Reexport.length' ('one' @('HashSet' a) x) ≡ 1 @ -} instance Hashable a => One (HashSet a) where
src/Relude/Container/Reexport.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Trustworthy #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Container.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports container-related data types, functions and typeclasses from @base@, @containers@ and @unordered-containers@ packages.
src/Relude/Debug.hs view
@@ -1,29 +1,34 @@ {-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeFamilies #-}+#if ( __GLASGOW_HASKELL__ < 906 ) {-# LANGUAGE TypeInType #-}+#endif {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} -#if __GLASGOW_HASKELL__ > 802-{-# LANGUAGE DerivingStrategies #-}-#endif- {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Debug+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module contains functions for debugging __pure__ functions. You can't use functions like 'System.IO.putStrLn' for this purpose because@@ -88,6 +93,9 @@ ) where import Data.Data (Data)+#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import GHC.Exts (RuntimeRep, TYPE) import GHC.TypeLits (ErrorMessage (..), TypeError) @@ -211,7 +219,7 @@ {-# WARNING traceM "'traceM' remains in code" #-} {-|-Like 'traceM', but uses 'Relude.show' on the argument to convert it to a+Like 'traceM', but uses 'Prelude.show' on the argument to convert it to a 'String'. >>> :{@@ -250,22 +258,9 @@ branch of code execution is not possible. __DO NOT USE__ 'error' as a normal error handling mechanism. -#ifdef mingw32_HOST_OS->>> error "oops"-*** Exception: oops-CallStack (from HasCallStack):- error, called at src\\Relude\\Debug.hs:288:11 in ...- ...-#else->>> error "oops"-*** Exception: oops-CallStack (from HasCallStack):- error, called at src/Relude/Debug.hs:288:11 in ...-...-#endif--⚠️__CAUTION__⚠️ Unlike "Prelude" version, 'error' takes 'Relude.Text' as an-argument. In case it used by mistake, the user will see the following:+⚠️__CAUTION__⚠️ Unlike "Prelude" version, 'error' takes+ t'Relude.String.Reexport.Text' as an argument. In case it used by mistake,+the user will see the following: >>> error ("oops" :: String) ...@@ -308,11 +303,7 @@ -- | Similar to 'undefined' but data type. data Undefined = Undefined-#if __GLASGOW_HASKELL__ > 802 deriving stock (Eq, Ord, Show, Read, Enum, Bounded, Data, Typeable, Generic)-#else- deriving (Eq, Ord, Show, Read, Enum, Bounded, Data, Typeable, Generic)-#endif {-# WARNING Undefined "'Undefined' type remains in code" #-} -- | 'Prelude.undefined' that leaves warning in code on every usage.
src/Relude/DeepSeq.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.DeepSeq+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module contains useful functions to evaluate expressions to weak-head normal form (WHNF) or just normal form (NF). Useful to force traces or @error@s
src/Relude/Enum.hs view
@@ -1,9 +1,12 @@+{-# LANGUAGE Safe #-}+ {- |-Copyright: (c) 2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Enum+Copyright : (c) 2021-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports 'Enum' related typeclasses and functions. Also introduces a few useful helpers to work with Enums.@@ -89,7 +92,7 @@ shared for every call. __Memory usage note:__ don't inverse functions that have types like 'Int'-as their result. In this case the created 'M.Map' will have huge size.+as their input. In this case the created 'M.Map' will have huge size. The complexity of reversed mapping is \(\mathcal{O}(\log n)\).
src/Relude/Exception.hs view
@@ -1,21 +1,18 @@-{-# LANGUAGE CPP #-}+{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE Safe #-} {-# LANGUAGE ViewPatterns #-} -#if __GLASGOW_HASKELL__ > 802-{-# LANGUAGE DerivingStrategies #-}-#endif- {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Exception+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Re-exports most useful functionality from the "Control.Exception" module. Also provides some convenient utilities to throw and handle exceptions.@@ -47,11 +44,7 @@ not meant to be ever executed, but happens to be executed anyway. -} data Bug = Bug SomeException CallStack-#if __GLASGOW_HASKELL__ > 802 deriving stock (Show)-#else- deriving (Show)-#endif instance Exception Bug where displayException (Bug e cStack) =
src/Relude/Extra.hs view
@@ -1,9 +1,10 @@ {- |-Copyright: (c) 2019-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra+Copyright : (c) 2019-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module exports all extra-related stuff. The extra modules are not exported by default, but you can easily bring them to@@ -48,27 +49,28 @@ import Relude.Extra.Type {- $Bifunctor-Additional combinators for 'Relude.Bifunctor'.+Additional combinators for t'Relude.Functor.Reexport.Bifunctor'. -} {- $CallStack-Useful functions to extract information from 'Relude.CallStack'.+Useful functions to extract information from t'Relude.Base.CallStack'. -} {- $Enum-Extra utilities for types that implement 'Relude.Bounded' and 'Relude.Enum'+Extra utilities for types that implement t'Relude.Enum.Bounded' and t'Relude.Enum.Enum' constraints. -} {- $Foldable-Extra folds for instances of the 'Relude.Foldable' typeclass.+Extra folds for instances of the t'Relude.Foldable.Reexport.Foldable' typeclass. Currently, just a short-circuitable left fold 'foldlSC'. -} {- $Foldable1-'Foldable1' is a typeclass like 'Relude.Foldable' but for non-empty structures.-For example, 'Relude.NonEmpty', 'Relude.Identity'.+'Foldable1' is a typeclass like t'Relude.Foldable.Reexport.Foldable' but for non-empty+structures. For example, t'Relude.List.NonEmpty.NonEmpty',+'Relude.Functor.Reexport.Identity'. 'Foldable1' has all type-safe and total methods like `head1`, `maximum1` in-contradiction with 'Data.Foldable.Foldable'.+contradiction with t'Relude.Foldable.Reexport.Foldable'. -} {- $Group
src/Relude/Extra/Bifunctor.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Bifunctor+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Useful combinators for bifunctors inside functors. This set of functions is useful when you want to work with types like these ones:
src/Relude/Extra/CallStack.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.CallStack+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Contains useful functions to work with GHC callstack.
src/Relude/Extra/Enum.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Enum+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Mini @bounded-enum@ framework inside @relude@.
src/Relude/Extra/Foldable.hs view
@@ -2,11 +2,12 @@ {-# LANGUAGE BangPatterns #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Foldable+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Contains utility functions for working with tuples.
src/Relude/Extra/Foldable1.hs view
@@ -1,5 +1,11 @@ {-# OPTIONS_GHC -Wno-redundant-constraints #-} +{-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE BangPatterns #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE Safe #-}@@ -8,12 +14,13 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2011-2015 Edward Kmett- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Foldable1+Copyright : (c) 2011-2015 Edward Kmett+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable 'Foldable1' is a typeclass like 'Data.Foldable.Foldable' but for non-empty structures. For example, 'Relude.NonEmpty', 'Relude.Identity'.@@ -88,7 +95,7 @@ 2 :| [] -} toNonEmpty :: f a -> NonEmpty a- toNonEmpty = foldMap1 (:|[])+ toNonEmpty = foldMap1 (:| []) {- | The first element of a non-empty data structure. @@ -210,7 +217,7 @@ {-# INLINE fold1 #-} toNonEmpty :: Identity a -> NonEmpty a- toNonEmpty = (:|[]) . coerce+ toNonEmpty = (:| []) . coerce {-# INLINE toNonEmpty #-} head1 :: Identity a -> a@@ -251,7 +258,7 @@ {-# INLINE fold1 #-} toNonEmpty :: (c, a) -> NonEmpty a- toNonEmpty (_, y) = (y :| [])+ toNonEmpty (_, y) = y :| [] {-# INLINE toNonEmpty #-} head1, last1 :: (c, a) -> a@@ -405,7 +412,7 @@ @since 1.0.0.0 -} average1 :: forall a f . (Foldable1 f, Fractional a) => f a -> a-average1 = uncurry (/) . foldl' (\(!total, !count) x -> (total + x, count + 1)) (0,0)+average1 = uncurry (/) . foldl' (\(!total, !count) x -> (total + x, count + 1)) (0, 0) {-# INLINE average1 #-} {-
src/Relude/Extra/Group.hs view
@@ -1,12 +1,14 @@-{-# LANGUAGE Safe #-}-{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE Safe #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Group+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Polymorphic grouping functions.
src/Relude/Extra/Lens.hs view
@@ -2,12 +2,13 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2012-2016 Edward Kmett- (c) 2019-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Lens+Copyright : (c) 2012-2016 Edward Kmett+ (c) 2019-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable @since 0.5.0 @@ -158,7 +159,6 @@ - [lens](https://hackage.haskell.org/package/lens) - [microlens](https://hackage.haskell.org/package/microlens) - [lens tutorial](http://hackage.haskell.org/package/lens-tutorial-1.0.3/docs/Control-Lens-Tutorial.html)- -} module Relude.Extra.Lens
src/Relude/Extra/Map.hs view
@@ -1,12 +1,15 @@-{-# LANGUAGE Trustworthy #-}-{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE Trustworthy #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Map+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Contains implementation of polymorphic type classes for data types 'Set' and 'Map'.@@ -25,9 +28,17 @@ , elems ) where +#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import GHC.Exts (IsList (Item, toList)) +#if MIN_VERSION_hashable(1,4,0)+import Relude.Base (Ord, Type)+#else import Relude.Base (Eq, Ord, Type)+#endif+ import Relude.Bool (Bool, guard, not) import Relude.Container.Reexport (HashMap, HashSet, Hashable, IntMap, IntSet, Map, Set, fst, snd) import Relude.Function ((.))@@ -79,7 +90,11 @@ @since 0.1.0 -}+#if MIN_VERSION_hashable(1,4,0)+instance (Hashable k) => StaticMap (HashMap k v) where+#else instance (Eq k, Hashable k) => StaticMap (HashMap k v) where+#endif type Key (HashMap k v) = k type Val (HashMap k v) = v @@ -124,7 +139,11 @@ @since 0.1.0 -}+#if MIN_VERSION_hashable(1,4,0)+instance (Hashable a) => StaticMap (HashSet a) where+#else instance (Eq a, Hashable a) => StaticMap (HashSet a) where+#endif type Key (HashSet a) = a type Val (HashSet a) = a @@ -236,7 +255,11 @@ @since 0.1.0 -}+#if MIN_VERSION_hashable(1,4,0)+instance (Hashable k) => DynamicMap (HashMap k v) where+#else instance (Eq k, Hashable k) => DynamicMap (HashMap k v) where+#endif insert = HM.insert {-# INLINE insert #-} insertWith = HM.insertWith
src/Relude/Extra/Newtype.hs view
@@ -1,12 +1,12 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Newtype+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Functions to ease work with @newtypes@. @@ -18,9 +18,7 @@ , wrap , under , under2-#if ( __GLASGOW_HASKELL__ != 802 ) , underF2-#endif , (#.) ) where @@ -88,7 +86,6 @@ under2 = coerce {-# INLINE under2 #-} -#if ( __GLASGOW_HASKELL__ != 802 ) {- | Version of 'under2' that works on @newtype@s parametrized by their representation. Provided for convenience. @@ -102,7 +99,6 @@ underF2 :: forall n a . Coercible a (n a) => (n a -> n a -> n a) -> (a -> a -> a) underF2 = coerce {-# INLINE underF2 #-}-#endif {- | Coercible composition. This function allows to write more efficient implementations of function compositions over @newtypes@.
src/Relude/Extra/Tuple.hs view
@@ -2,11 +2,12 @@ {-# LANGUAGE TupleSections #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Tuple+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Contains utility functions for working with tuples. @@ -118,7 +119,7 @@ mapToFst :: (a -> b) -> a -> (b, a) mapToFst = toFst {-# INLINE mapToFst #-}-{-# DEPRECATED mapToFst "Use 'toFst' from 'Relude.Extra.Tuple' instead" #-}+{-# DEPRECATED mapToFst "Use 'toFst' from [Tuple](\"Relude.Extra.Tuple\") instead" #-} {- | Apply a function, with the result in the second slot, and the value in the other.@@ -133,7 +134,7 @@ mapToSnd :: (a -> b) -> a -> (a, b) mapToSnd = toSnd {-# INLINE mapToSnd #-}-{-# DEPRECATED mapToSnd "Use 'toSnd' from 'Relude.Extra.Tuple' instead" #-}+{-# DEPRECATED mapToSnd "Use 'toSnd' from [Tuple](\"Relude.Extra.Tuple\") instead" #-} {- | Apply a function that returns a value inside of a functor, with the output in the first slot, the input in the second,
src/Relude/Extra/Type.hs view
@@ -9,11 +9,12 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Experimental-Portability: Portable+Module : Relude.Extra.Type+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Contains useful utilities to work with Types. @@ -34,8 +35,14 @@ import Type.Reflection (typeRep) +#if ( __GLASGOW_HASKELL__ >= 906 ) -- $setup--- >>> :set -XDataKinds -XTypeOperators+-- >>> :set -XAllowAmbiguousTypes -XDataKinds -XExplicitNamespaces -XPolyKinds -XTypeFamilies -XTypeOperators -XUndecidableInstances+-- >>> :set -fprint-redundant-promotion-ticks+#else+-- $setup+-- >>> :set -XAllowAmbiguousTypes -XDataKinds -XExplicitNamespaces -XPolyKinds -XTypeFamilies -XTypeOperators -XUndecidableInstances+#endif {- | Gets a string representation of a type. @@ -58,7 +65,18 @@ {- | Concatenates type-level lists. -#if ( __GLASGOW_HASKELL__ >= 806 )+#if ( __GLASGOW_HASKELL__ >= 902 )++>>> :kind! '[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1]+'[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1] :: [Maybe+ Natural]+= '[ 'Just 5, 'Nothing, 'Just 3, 'Nothing, 'Just 1]++>>> :kind! '[] ++ '[ 'Just 3, 'Nothing, 'Just 1]+'[] ++ '[ 'Just 3, 'Nothing, 'Just 1] :: [Maybe Natural]+= '[ 'Just 3, 'Nothing, 'Just 1]++#elif ( __GLASGOW_HASKELL__ >= 806 ) >>> :kind! '[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1] '[ 'Just 5, 'Nothing] ++ '[ 'Just 3, 'Nothing, 'Just 1] :: [Maybe
src/Relude/File.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.File+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted to 'MonadIO' families of file processing functions for the 'Text', 'LText', 'ByteString' and 'LByteString' types.@@ -20,6 +21,15 @@ data with the help of functions from the "Relude.String.Conversion" module, e. g. 'Relude.String.Conversion.decodeUtf8'. +To be more precise, avoid the following functions:++* 'readFileText'+* 'readFileLText'++See the following blog post for more details:++* [Beware of readFile by Michael Snoyman](https://www.snoyman.com/blog/2016/12/beware-of-readfile/)+ @since 0.3.0 -} @@ -68,6 +78,7 @@ readFileText = liftIO . T.readFile {-# SPECIALIZE readFileText :: FilePath -> IO Text #-} {-# INLINE readFileText #-}+{-# WARNING readFileText ["'readFileText' depends on the system's locale settings and can throw unexpected exceptions.", "Use 'readFileBS' instead."] #-} {- | Lifted version of 'T.writeFile'. @@ -99,6 +110,7 @@ readFileLText = liftIO . LT.readFile {-# SPECIALIZE readFileLText :: FilePath -> IO LText #-} {-# INLINE readFileLText #-}+{-# WARNING readFileLText ["'readFileLText' depends on the system's locale settings and can throw unexpected exceptions.", "Use 'readFileLBS' instead."] #-} {- | Lifted version of 'LT.writeFile'.
src/Relude/Foldable.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Foldable+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module provides 'Foldable' and 'Traversable' related types and functions. -}
src/Relude/Foldable/Fold.hs view
@@ -1,5 +1,11 @@ {-# OPTIONS_GHC -Wno-redundant-constraints #-} +{-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE Safe #-}@@ -8,13 +14,14 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Foldable.Fold+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Fixes and additions to 'Foldable'. Specifically: @@ -72,7 +79,7 @@ flipfoldl' f = foldl' (flip f) {-# INLINE flipfoldl' #-} -{- | Alternative version of 'Relude.asum' that takes a function to map over.+{- | Alternative version of 'Relude.Foldable.Reexport.asum' that takes a function to map over. >>> asumMap (\x -> if x > 2 then Just x else Nothing) [1..4] Just 3@@ -83,7 +90,7 @@ asumMap = coerce (foldMap :: (a -> Alt m b) -> f a -> Alt m b) {-# INLINE asumMap #-} -{- | Polymorphic version of the 'Relude.concatMapA' function.+{- | Polymorphic version of the 'concatMapA' function. >>> foldMapA @[Int] (Just . replicate 3) [1..3] Just [1,1,1,2,2,2,3,3,3]@@ -98,7 +105,7 @@ foldMapA = coerce (foldMap :: (a -> Ap m b) -> f a -> Ap m b) {-# INLINE foldMapA #-} -{- | Polymorphic version of the 'Relude.concatMapM' function.+{- | Polymorphic version of the 'Control.Monad.Extra.concatMapM' function. >>> foldMapM @[Int] (Just . replicate 3) [1..3] Just [1,1,1,2,2,2,3,3,3]
src/Relude/Foldable/Reexport.hs view
@@ -2,11 +2,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Foldable.Reexport+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports "Data.Foldable" and "Data.Traversable". -}@@ -26,8 +27,8 @@ #if MIN_VERSION_base(4,13,0) import Data.Foldable (foldMap') #endif-import Data.Traversable (Traversable (..), forM, mapAccumL, mapAccumR) import Data.Bifoldable (Bifoldable (..), biList, biall, biand, biany, biasum, bielem, bifind, bifoldl', bifoldlM, bifoldr', bifoldrM, bifor_, bilength, binull, bior, bisequence_, bitraverse_) import Data.Bitraversable (Bitraversable (..), bifoldMapDefault, bifor, bimapDefault, bisequence)+import Data.Traversable (Traversable (..), forM, mapAccumL, mapAccumR)
src/Relude/Function.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Function+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module reexports very basic and primitive functions and function combinators.
src/Relude/Functor.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Functor+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Convenient functions to work with 'Functor'. -}
src/Relude/Functor/Fmap.hs view
@@ -2,13 +2,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Functor.Fmap+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module contains useful functions to work with 'Functor' type class. -}
src/Relude/Functor/Reexport.hs view
@@ -2,25 +2,29 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Functor.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports functionality regarding 'Functor' and 'Bifunctor' typeclasses. -} module Relude.Functor.Reexport- ( module Data.Bifunctor- , module Data.Functor+ ( -- * Reexport Functor+ module Data.Functor , module Data.Functor.Compose , module Data.Functor.Identity #if MIN_VERSION_base(4,12,0) , module Data.Functor.Contravariant #endif++ -- * Reexport Bifunctor+ , module Data.Bifunctor ) where import Data.Bifunctor (Bifunctor (..))
src/Relude/Lifted.hs view
@@ -1,64 +1,65 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted versions of base functions. These functions are lifted in a sense that you can use them inside various-monad transformers without adding 'Relude.liftIO' calls explicitly. However, you still-can use all these functions inside plain 'Relude.IO' monad as usual.+monad transformers without adding 'Relude.Monad.Reexport.liftIO' calls+explicitly. However, you still can use all these functions inside plain+ t'Relude.Base.IO' monad as usual. === Example ==== @base@ With the @base@ function, you can easily work with these functions in the-'Relude.IO' monad:+ t'Relude.Base.IO' monad: @-__main__ :: 'Relude.IO' ()+__main__ :: t'Relude.Base.IO' () __main__ = __do__ x <- 'Data.Text.getLine' 'Prelude.print' x @ -However, to work in 'Relude.MonadIO' you already need to "lift" them:+However, to work in t'Relude.Monad.Reexport.MonadIO' you already need to "lift" them: @-__main__ :: 'Relude.MonadIO' m => m ()+__main__ :: t'Relude.Monad.Reexport.MonadIO' m => m () __main__ = __do__- x <- 'Relude.liftIO' 'Data.Text.getLine'- 'Relude.liftIO' ('Prelude.print' x)+ x <- 'Relude.Monad.Reexport.liftIO' 'Data.Text.getLine'+ 'Relude.Monad.Reexport.liftIO' ('Prelude.print' x) @ ==== @relude@ -In the meantime, @relude@ provides these function that can work in 'Relude.IO'+In the meantime, @relude@ provides these function that can work in t'Relude.Base.IO' the same way: @-__main__ :: 'Relude.IO' ()+__main__ :: t'Relude.Base.IO' () __main__ = __do__ x <- 'getLine' 'print' x @ -But also allows you to work in the 'Relude.MonadIO' monads more easily:+But also allows you to work in the t'Relude.Monad.Reexport.MonadIO' monads more easily: @-__main__ :: 'Relude.MonadIO' m => m ()+__main__ :: t'Relude.Monad.Reexport.MonadIO' m => m () __main__ = __do__ x <- 'getLine' 'print' x @- -} module Relude.Lifted@@ -93,7 +94,7 @@ Lifted versions of functions that work with exit processes. -} {- $file-Lifted versions of functions working with files and common 'Relude.IO'.+Lifted versions of functions working with files and common t'Relude.Base.IO'. -} {- $ioref Lifted reexports from "Data.IORef" module.@@ -102,7 +103,7 @@ Lifted functions to work with stdin and stdout. -} {- $handle-Lifted functions to work with 'Relude.Base.IO' 'Handle's.+Lifted functions to work with t'Relude.Base.IO' 'Handle's. -} {- $env Lifted functions to work with system environment.
src/Relude/Lifted/Concurrent.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.Concurrent+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted 'MVar' and 'STM' functions. -}
src/Relude/Lifted/Env.hs view
@@ -1,9 +1,12 @@+{-# LANGUAGE Safe #-}+ {- |-Copyright: (c) 2020-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.Env+Copyright : (c) 2020-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted functions to work with system environment.
src/Relude/Lifted/Exit.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.Exit+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted versions of functions that work with exit processes. -}
src/Relude/Lifted/File.hs view
@@ -2,13 +2,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.File+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted versions of functions working with files and common IO. -}@@ -35,6 +36,7 @@ readFile = liftIO . IO.readFile {-# SPECIALIZE readFile :: FilePath -> IO String #-} {-# INLINE readFile #-}+{-# WARNING readFile ["'readFile' depends on the system's locale settings and can throw unexpected exceptions.", "Use 'readFileBS' or 'readFileLBS' instead."] #-} #if ( __GLASGOW_HASKELL__ >= 900 ) {- | Lifted version of 'IO.readFile''. Strict version of 'readFile'.@@ -45,6 +47,7 @@ readFile' = liftIO . IO.readFile' {-# SPECIALIZE readFile' :: FilePath -> IO String #-} {-# INLINE readFile' #-}+{-# WARNING readFile' ["readFile' depends on the system's locale settings and can throw unexpected exceptions.", "Use 'readFileBS' or 'readFileLBS' instead."] #-} #endif -- | Lifted version of 'IO.writeFile'.
src/Relude/Lifted/Handle.hs view
@@ -1,9 +1,12 @@+{-# LANGUAGE Safe #-}+ {- |-Copyright: (c) 2020-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.Handle+Copyright : (c) 2020-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted functions to work with 'IO' 'Handle's.
src/Relude/Lifted/IORef.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.IORef+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted reexports from "Data.IORef" module. -}
src/Relude/Lifted/Terminal.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Lifted.Terminal+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Lifted functions to work with stdin and stdout.
src/Relude/List.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.List+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Utility functions to work with lists and 'NonEmpty' lists. -}
src/Relude/List/NonEmpty.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE Safe #-}@@ -6,13 +12,14 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.List.NonEmpty+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module contains reexports from "Data.List.NonEmpty" and safe functions to work with list type in terms of 'NonEmpty'.@@ -87,6 +94,9 @@ ) where import Data.List.NonEmpty (NonEmpty (..), nonEmpty)+#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import GHC.TypeLits (ErrorMessage (..), Symbol, TypeError) import Relude.Applicative (Applicative, pass)
src/Relude/List/Reexport.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Trustworthy #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.List.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports most of the "Data.List". -}
src/Relude/Monad.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monad+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexporting useful monadic stuff. -}@@ -52,7 +53,7 @@ {- | Repeat a monadic action indefinitely. -This is a more type safe version of 'forever', which has a convinient+This is a more type safe version of 'forever', which has a convenient but unsafe type. Consider the following two examples. In the @getIntForever@ functions, it@@ -79,10 +80,10 @@ Reexports functions to work with different monads. -} {- $maybe-Provided new combinators to work with 'Relude.Maybe' data type.+Provided new combinators to work with 'Relude.Monad.Reexport.Maybe' data type. -} {- $either-Provided new combinators to work with 'Relude.Either' data type.+Provided new combinators to work with 'Relude.Monad.Reexport.Either' data type. -} {- $trans Monad transformers functions and combinators.
src/Relude/Monad/Either.hs view
@@ -3,15 +3,16 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monad.Either+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable -Utilities to work with 'Relude.Either' data type.+Utilities to work with 'Relude.Monad.Reexport.Either' data type. -} module Relude.Monad.Either
src/Relude/Monad/Maybe.hs view
@@ -1,15 +1,16 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monad.Maybe+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable -Utility functions to work with 'Relude.Maybe' data type as monad.+Utility functions to work with 'Relude.Monad.Reexport.Maybe' data type as monad. -} module Relude.Monad.Maybe@@ -48,7 +49,7 @@ mA ?: b = fromMaybe b mA {-# INLINE (?:) #-} -{- | Specialized version of 'Relude.for_' for 'Maybe'. It's used for code readability.+{- | Specialized version of 'Relude.Foldable.Reexport.for_' for 'Maybe'. It's used for code readability. Also helps to avoid space leaks: <http://www.snoyman.com/blog/2017/01/foldable-mapm-maybe-and-recursive-functions Foldable.mapM_ space leak>.@@ -97,7 +98,7 @@ whenNothing_ _ _ = pass {-# INLINE whenNothing_ #-} -{- | Monadic version of 'whenNothingM'.+{- | Monadic version of 'whenNothing'. >>> whenNothingM (pure $ Just True) $ True <$ putTextLn "Is Just!" True@@ -109,7 +110,7 @@ whenNothingM mm action = mm >>= \m -> whenNothing m action {-# INLINE whenNothingM #-} -{- | Monadic version of 'whenNothingM_'.+{- | Monadic version of 'whenNothing_'. >>> whenNothingM_ (pure $ Just True) $ putTextLn "Is Just!" >>> whenNothingM_ (pure Nothing) $ putTextLn "Is Nothing!"
src/Relude/Monad/Reexport.hs view
@@ -1,25 +1,29 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monad.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports functions to work with monads. -} module Relude.Monad.Reexport- ( -- * Reexport transformers- module Control.Monad.Except+ ( -- * Reexport MonadIO+ MonadIO (liftIO)++ -- * Reexport transformers+ , module Control.Monad.Except , module Control.Monad.Reader , module Control.Monad.State.Strict , module Control.Monad.Trans , module Control.Monad.Trans.Identity- , module Control.Monad.Trans.Maybe+ , module Control.Monad.Trans.Maybe -- * Reexport monadic functions , module Control.Monad@@ -33,13 +37,14 @@ ) where -- Monad transformers+import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Except (ExceptT (..), runExceptT) import Control.Monad.Reader (MonadReader, Reader, ReaderT (..), ask, asks, local, reader, runReader, withReader, withReaderT) import Control.Monad.State.Strict (MonadState, State, StateT (..), evalState, evalStateT, execState, execStateT, get, gets, modify, modify', put, runState, state, withState)-import Control.Monad.Trans (MonadIO, MonadTrans, lift, liftIO)+import Control.Monad.Trans (MonadTrans, lift) import Control.Monad.Trans.Identity (IdentityT (runIdentityT)) import Control.Monad.Trans.Maybe (MaybeT (..), exceptToMaybeT, maybeToExceptT)
src/Relude/Monad/Trans.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Trustworthy #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monad.Trans+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Monad transformers utilities. -}@@ -85,7 +86,7 @@ For a detailed explanation, refer to the following blog post: -* <https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT Faster Winter 5: Eta-Expanding ReaderT (by Joachim Breitners)>+* <https://www.joachim-breitner.de/blog/763-Faster_Winter_5__Eta-Expanding_ReaderT Faster Winter 5: Eta-Expanding ReaderT (by Joachim Breitner)> @since 0.7.0.0 -}
src/Relude/Monoid.hs view
@@ -5,20 +5,21 @@ {-# LANGUAGE Trustworthy #-} #else {-# LANGUAGE Safe #-}-#endif {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Monoid+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports functions to work with monoids plus adds extra useful functions. -} +#endif module Relude.Monoid ( -- * Reexports module Data.Monoid@@ -37,8 +38,8 @@ #endif import Data.Monoid (All (..), Alt (..), Any (..), Dual (..), Endo (..), First (..), Last (..), Monoid (..), Product (..), Sum (..))-import Data.Semigroup (Option (..), Semigroup (sconcat, stimes, (<>)), WrappedMonoid, cycle1,- mtimesDefault, stimesIdempotent, stimesIdempotentMonoid, stimesMonoid)+import Data.Semigroup (Semigroup (sconcat, stimes, (<>)), WrappedMonoid, cycle1, mtimesDefault,+ stimesIdempotent, stimesIdempotentMonoid, stimesMonoid) import Relude.Bool.Reexport (Bool (..)) import Relude.Monad.Reexport (Maybe, fromMaybe)@@ -61,7 +62,7 @@ -- >>> import Relude.Monad (Maybe (..)) -- >>> import Relude.Numeric (Int) -{- | Extracts 'Monoid' value from 'Maybe' returning 'mempty' if 'Relude.Nothing'.+{- | Extracts 'Monoid' value from 'Maybe' returning 'mempty' if 'Relude.Monad.Reexport.Nothing'. >>> maybeToMonoid (Just [1,2,3] :: Maybe [Int]) [1,2,3]
src/Relude/Nub.hs view
@@ -2,13 +2,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Nub+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Functions to remove duplicates from a list. @@ -41,7 +42,7 @@ ( hashNub , ordNub -#if __GLASGOW_HASKELL__ > 804+#if MIN_VERSION_containers(0,6,0) , ordNubOn , intNub , intNubOn@@ -51,14 +52,16 @@ , unstableNub ) where +#if !MIN_VERSION_hashable(1,4,0) import Data.Eq (Eq)+#endif import Data.Hashable (Hashable) import Data.HashSet as HashSet import Data.Ord (Ord) import Prelude (Int, (.)) import qualified Data.Set as Set-#if __GLASGOW_HASKELL__ > 804+#if MIN_VERSION_containers(0,6,0) import qualified Data.Containers.ListUtils as Containers #endif @@ -66,7 +69,7 @@ -- $setup -- >>> import Prelude (div, fromEnum) -{- | Removes duplicate elements from a list, keeping only the first occurance of+{- | Removes duplicate elements from a list, keeping only the first occurrence of the element. Like 'Prelude.nub' but runs in \( O(n \log n) \) time and requires 'Ord'.@@ -76,7 +79,7 @@ -} ordNub :: forall a . (Ord a) => [a] -> [a]-#if __GLASGOW_HASKELL__ > 804+#if MIN_VERSION_containers(0,6,0) ordNub = Containers.nubOrd {-# INLINE ordNub #-} #else@@ -92,7 +95,7 @@ #endif -#if __GLASGOW_HASKELL__ > 804+#if MIN_VERSION_containers(0,6,0) {- | Similar to 'ordNub' but performs nub through the mapped list on the given function. @@ -112,7 +115,11 @@ [3,2,-1,1] -}+#if MIN_VERSION_hashable(1,4,0)+hashNub :: forall a . (Hashable a) => [a] -> [a]+#else hashNub :: forall a . (Eq a, Hashable a) => [a] -> [a]+#endif hashNub = go HashSet.empty where go :: HashSet.HashSet a -> [a] -> [a]@@ -139,17 +146,20 @@ [1,2,3,-1] -}+#if MIN_VERSION_hashable(1,4,0)+unstableNub :: (Hashable a) => [a] -> [a]+#else unstableNub :: (Eq a, Hashable a) => [a] -> [a]+#endif unstableNub = HashSet.toList . HashSet.fromList {-# INLINE unstableNub #-} -#if __GLASGOW_HASKELL__ > 804-+#if MIN_VERSION_containers(0,6,0) {- | Removes duplicate elements from a list, keeping only the first occurance of the element. -Like 'Prelude.nub' but runs in \( O(n \min\(n, int_bits\)) \) time and requires 'Ord'.+Like 'Prelude.nub' but runs in \( O (n \min (n, int\_bits )) \) time and requires 'Ord'. >>> intNub [3, 3, 3, 2, 2, -1, 1] [3,2,-1,1]
src/Relude/Numeric.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE Trustworthy #-} {- |-Copyright: (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Numeric+Copyright : (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Provides numerical data types and functions.
src/Relude/Print.hs view
@@ -4,13 +4,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Print+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Functions like 'Prelude.putStr' and 'Prelude.putStrLn' but for 'Text', 'LText', 'ByteString' and 'LByteString'.
src/Relude/String.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Safe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.String+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Type classes for conversion between different string representations. @@ -36,7 +37,6 @@ +-----------------------+---------------------+--------------+--------------+--------------------+------------------------+--------------------------+ | __'ShortByteString'__ | 'decodeUtf8' | 'decodeUtf8' | 'fromShort' | 'decodeUtf8' |@'toLazy' . 'fromShort'@| ~ | +-----------------------+---------------------+--------------+--------------+--------------------+------------------------+--------------------------+- -} module Relude.String
src/Relude/String/Conversion.hs view
@@ -1,4 +1,9 @@ {-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FunctionalDependencies #-}@@ -10,13 +15,14 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.String.Conversion+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable This module implements type class which allow to have conversion to and from 'Relude.String.Reexport.Text', 'String' and 'ByteString' types@@ -100,8 +106,17 @@ >>> decodeUtf8 @Text @ByteString "\208\208\176\209\130\208\176\208\186" "\65533\65533\1090\1072\1082" #endif++#if MIN_VERSION_text(2,0,2) >>> decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"- Left Cannot decode byte '\xd0': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream+ Left Cannot decode byte '\xd0': ...: Invalid UTF-8 stream+#elif MIN_VERSION_text(2,0,0)+ >>> decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"+ Left Cannot decode byte '\xd0': ...: Invalid UTF-8 stream+#else+ >>> decodeUtf8Strict @Text @ByteString "\208\208\176\209\130\208\176\208\186"+ Left Cannot decode byte '\xd0': ...: Invalid UTF-8 stream+#endif -} decodeUtf8Strict :: b -> Either T.UnicodeException a
src/Relude/String/Reexport.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE CPP #-}++#if __GLASGOW_HASKELL__ >= 902+{-# OPTIONS_GHC -Wno-operator-whitespace #-}+#endif+ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-}@@ -7,13 +13,14 @@ {-# LANGUAGE UndecidableInstances #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.String.Reexport+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable Reexports functions to work with 'Data.Text.Text', 'ByteString' and 'ShortByteString' types.@@ -49,6 +56,9 @@ import Data.Text.Encoding (decodeUtf8', decodeUtf8With) import Data.Text.Encoding.Error (OnDecodeError, OnError, UnicodeException, lenientDecode, strictDecode)+#if __GLASGOW_HASKELL__ >= 904+import Data.Type.Equality (type (~))+#endif import GHC.TypeLits (ErrorMessage (..), Symbol, TypeError) import Text.Read (Read, readMaybe, reads)
src/Relude/Unsafe.hs view
@@ -1,13 +1,14 @@ {-# LANGUAGE Unsafe #-} {- |-Copyright: (c) 2016 Stephen Diehl- (c) 2016-2018 Serokell- (c) 2018-2021 Kowainik-SPDX-License-Identifier: MIT-Maintainer: Kowainik <xrom.xkov@gmail.com>-Stability: Stable-Portability: Portable+Module : Relude.Unsafe+Copyright : (c) 2016 Stephen Diehl+ (c) 2016-2018 Serokell+ (c) 2018-2023 Kowainik+SPDX-License-Identifier : MIT+Maintainer : Kowainik <xrom.xkov@gmail.com>+Stability : Stable+Portability : Portable __⚠️ Warning ⚠️__ @@ -17,9 +18,9 @@ +-----------------------------------+---------------------------------------------------------------------+ | __Partial__ | __Total__ | +===================================+=====================================================================+-| @'head' :: [a] -> a@ | @'Relude.head' :: NonEmpty a -> a@ |+| @'head' :: [a] -> a@ | @'Relude.List.NonEmpty.head' :: NonEmpty a -> a@ | +-----------------------------------+---------------------------------------------------------------------+-| @'tail' :: [a] -> [a]@ | @'Relude.tail' :: NonEmpty a -> [a]@ |+| @'tail' :: [a] -> [a]@ | @'Relude.List.NonEmpty.tail' :: NonEmpty a -> [a]@ | +-----------------------------------+---------------------------------------------------------------------+ | @'read' :: Read a => String -> a@ | @'Relude.String.Reexport.readMaybe' :: Read a => String -> Maybe a@ | +-----------------------------------+---------------------------------------------------------------------+
test/Doctest.hs view
@@ -9,7 +9,8 @@ main = do sourceFiles <- glob "src/**/*.hs" doctest- $ "-XInstanceSigs"+ $ "-XHaskell2010"+ : "-XInstanceSigs" : "-XNoImplicitPrelude" : "-XOverloadedStrings" : "-XScopedTypeVariables"