-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bellroy/initial
Add timeline packages
- Loading branch information
Showing
18 changed files
with
1,023 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode/ | ||
.direnv/ | ||
.envrc | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelog | ||
|
||
## 0.1.0.0 | ||
- Open source the timeline library we use internally at Bellroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Copyright (C) 2023 Bellroy Pty Ltd | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the | ||
distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
# timeline | ||
|
||
Provides a container type `Timeline a` for handling data that changes over time. | ||
## Motivation | ||
|
||
The world is always changing, and often we want to manage the changes of data | ||
using computers. Below are some concrete examples: | ||
|
||
- Employee data such as compensation, city, tax rule, time-off, etc. | ||
- Prices of products. A product could have different prices on Amazon and EBay, | ||
and in different currencies. | ||
|
||
Timeline data is often implemented by attaching extra fields to your business | ||
object, denoting the start and end time of each interval. However, only | ||
representing and storing the data is not sufficient, we need to run operations | ||
on timeline data, like extracting a single data point at some specific time, | ||
merging multiple timelines together, etc. | ||
|
||
If you have a similar use case and don't want to reinvent the wheel, this | ||
library is for you. | ||
|
||
## Package Organization | ||
|
||
- `timeline` essential types and functions | ||
- `timeline-tests` unit tests | ||
- `timeline-hedgehog` hedgehog generators for timeline types | ||
|
||
## Getting Started | ||
|
||
The core type is `Timeline a`, refer to | ||
[Haddock](https://hackage.haskell.org/package/timeline-0.0.1.0/docs/Data-Timeline.html) | ||
for its usage. | ||
|
||
## Contribution | ||
Bellroy actively maintains this project. Feel free to submit issues and | ||
pull requests! | ||
|
||
The code is formatted with [`ormolu`](https://hackage.haskell.org/package/ormolu) | ||
|
||
If you use Nix: | ||
- `nix develop` enter a shell with all necessary tools | ||
- `nix build` build and run tests on all GHC versions we support | ||
- Use `nix flake show` to view a full list of outputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packages: ./ | ||
tests: True |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
# Use 'nix flake show' to discover the structure of the output. | ||
# Multiple versions of compiler is supported. | ||
inputs = { | ||
nixpkgs.url = "nixpkgs/nixpkgs-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
flake-compat = { | ||
url = "github:edolstra/flake-compat"; | ||
flake = false; | ||
}; | ||
}; | ||
|
||
outputs = inputs: | ||
let | ||
cabalPackages = [ | ||
{ | ||
name = "timeline"; | ||
path = ./package.nix; | ||
} | ||
]; | ||
supportedCompilers = [ "ghc8107" "ghc926" "ghc944" ]; | ||
defaultCompiler = "ghc926"; | ||
in | ||
inputs.flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
nixpkgs = import inputs.nixpkgs { inherit system; }; | ||
|
||
makePackageSet = haskellPackages: haskellPackages.override { | ||
overrides = final: prev: with nixpkgs.haskell.lib; | ||
builtins.listToAttrs | ||
( | ||
builtins.map | ||
(cabalPackage: { | ||
name = cabalPackage.name; | ||
value = prev.callPackage cabalPackage.path { }; | ||
}) | ||
cabalPackages | ||
); | ||
}; | ||
|
||
essentialTools = with nixpkgs; [ | ||
cabal-install | ||
hlint | ||
ormolu | ||
haskellPackages.cabal-fmt | ||
cabal2nix | ||
miniserve | ||
]; | ||
|
||
makeShell = haskellPackages: (makePackageSet haskellPackages).shellFor { | ||
packages = p: builtins.map (cabalPackage: p.${cabalPackage.name}) cabalPackages; | ||
withHoogle = true; | ||
buildInputs = essentialTools ++ [ | ||
nixpkgs.haskellPackages.haskell-language-server | ||
]; | ||
}; | ||
|
||
lightShell = nixpkgs.mkShell { | ||
packages = essentialTools ++ [ nixpkgs.ghc ]; | ||
}; | ||
in | ||
{ | ||
packages = | ||
let packagesWithoutDefault = | ||
builtins.listToAttrs | ||
( | ||
builtins.concatMap | ||
(compilerName: | ||
let pkgSet = makePackageSet nixpkgs.haskell.packages.${compilerName}; | ||
in | ||
builtins.map | ||
(cabalPackage: { | ||
name = "${compilerName}-${cabalPackage.name}"; | ||
value = pkgSet.${cabalPackage.name}; | ||
}) | ||
cabalPackages | ||
) | ||
supportedCompilers | ||
); | ||
in | ||
packagesWithoutDefault // { | ||
default = nixpkgs.runCommand "aggregate" | ||
{ | ||
buildInputs = builtins.map (name: packagesWithoutDefault.${name}) | ||
(builtins.attrNames packagesWithoutDefault); | ||
} "touch $out"; | ||
}; | ||
|
||
devShells = | ||
let devShellsWithoutDefault = | ||
builtins.listToAttrs | ||
( | ||
builtins.map | ||
(compilerName: { | ||
name = compilerName; | ||
value = makeShell nixpkgs.haskell.packages.${compilerName}; | ||
}) | ||
supportedCompilers | ||
); in | ||
devShellsWithoutDefault // { | ||
default = devShellsWithoutDefault.${defaultCompiler}; | ||
light = lightShell; | ||
}; | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ mkDerivation, base, bytestring, containers, hashable, hedgehog | ||
, indexed-traversable, lib, semigroupoids, tasty, tasty-discover | ||
, tasty-golden, tasty-hedgehog, tasty-hunit, template-haskell, text | ||
, th-compat, time, transformers | ||
}: | ||
mkDerivation { | ||
pname = "timeline"; | ||
version = "0.1.0.0"; | ||
src = ./.; | ||
libraryHaskellDepends = [ | ||
base containers hedgehog indexed-traversable semigroupoids | ||
template-haskell text th-compat time | ||
]; | ||
testHaskellDepends = [ | ||
base bytestring containers hashable hedgehog indexed-traversable | ||
tasty tasty-golden tasty-hedgehog tasty-hunit text time | ||
transformers | ||
]; | ||
testToolDepends = [ tasty-discover ]; | ||
description = "Data type representing a piecewise-constant function over time"; | ||
license = lib.licenses.bsd3; | ||
} |
Oops, something went wrong.