Commit graph

5 commits

Author SHA1 Message Date
sterni
bef44b2042 refactor(nix/tag): use throw over lib.assertMsg
Slightly prettier error message etc.

Change-Id: I9af4ec6ce337c65b5ca0820dc15a4e084832c529
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3542
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
2021-10-24 20:25:10 +00:00
sterni
3a8e8120de feat(nix/tag): add functions for querying a tag's name and value
Both are just trivial wrappers around assertIsTag to make these lookups
more ergonomic. This also allows us to demote assertIsTag to an
implemtation detail.

Change-Id: Ib6ba2a858f4839354a57b660042b418976c4b1d9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3541
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
2021-09-14 14:02:03 +00:00
sterni
1883159f92 docs(nix/tag): correct comment for assertIsTag
Change-Id: Id54cc3a1d7c83c6a94b9446c76b00ca2ce1ab48e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3540
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
2021-09-14 14:02:03 +00:00
sterni
596344faf4 docs(nix/tag): fix example for discrDef
Change-Id: I8b7accb399448f57ace502642bd91fcfae416f15
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3507
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
2021-09-10 11:08:03 +00:00
Profpatsch
e4a7704583 feat(nix): add nix.tag, a way of discriminating via tagged unions
Introduces the concept of a “tag”, a single-keyed attrset which
annotates a nix value with a name.
This can be used to implement tagged unions (by implying the list of
possible tags is well-known), which has some overlap with how
`nix.yants` does it.

However, the more fascinating use-case is in concert with a
so-called discriminator, `match` and hylomorphisms.

The discriminator can take a nix value, and add tags to it based on
some predicate.
With `match`, we can then use that information to convert the
discriminated values again.
With `hylo`, we can combine both the “constructive” discriminator step
with the “destructive” match step to recursively walk over a nix data
structure (based on a description of how to recurse, e.g. through attrset
values or list values), and then apply a transformation in one go.

Change-Id: Ia335ca8b0881447fbbcb6bcd80f49feb835f1715
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2434
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
2021-01-30 15:41:08 +00:00