Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeline packages #1

Merged
merged 24 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/
.direnv/
.envrc
result
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
29 changes: 29 additions & 0 deletions LICENSE
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.
41 changes: 40 additions & 1 deletion README.md
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
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: ./
tests: True
59 changes: 59 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 106 additions & 0 deletions flake.nix
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;
};
}
);
}
22 changes: 22 additions & 0 deletions package.nix
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;
}
Loading