1{-# language DataKinds #-}
2{-# language FlexibleContexts #-}
4{-# language LambdaCase #-}
5{-# language MultiParamTypeClasses #-}
6{-# language StandaloneKindSignatures #-}
7{-# language TypeFamilies #-}
8{-# language UndecidableInstances #-}
10module Rel8.Column.NonEmpty
11 ( HNonEmpty, AHNonEmpty(..)
16import Data.Kind ( Type )
17import Data.List.NonEmpty ( NonEmpty )
21import Rel8.Aggregate ( Aggregate )
22import Rel8.Expr ( Expr )
23import Rel8.Kind.Context ( SContext(..), Reifiable( contextSing ) )
24import Rel8.Schema.Context ( Col )
25import Rel8.Schema.HTable.NonEmpty ( HNonEmptyTable )
26import Rel8.Schema.Insert ( Insert )
27import qualified Rel8.Schema.Kind as K
28import Rel8.Schema.Name ( Name )
29import Rel8.Schema.Reify ( Reify, hreify, hunreify )
30import Rel8.Schema.Result ( Result )
32 ( Table, Columns, Congruent, Context, fromColumns, toColumns
33 , Unreify, reify, unreify
35import Rel8.Table.NonEmpty ( NonEmptyTable( NonEmptyTable ) )
36import Rel8.Table.Recontextualize ( Recontextualize )
37import Rel8.Table.Unreify ( Unreifiable )
40type HNonEmpty :: K.Context -> Type -> Type
41type family HNonEmpty context where
42 HNonEmpty (Reify context) = AHNonEmpty context
43 HNonEmpty Aggregate = NonEmptyTable
44 HNonEmpty Expr = NonEmptyTable
45 HNonEmpty Insert = NonEmptyTable
46 HNonEmpty Name = NonEmptyTable
47 HNonEmpty Result = NonEmpty
50type AHNonEmpty :: K.Context -> Type -> Type
51newtype AHNonEmpty context a = AHNonEmpty (HNonEmpty context a)
56 , Table (Reify context) a
57 , Unreifiable (Reify context) a
59 => Table (Reify context) (AHNonEmpty context a)
61 type Context (AHNonEmpty context a) = Reify context
62 type Columns (AHNonEmpty context a) = HNonEmptyTable (Columns a)
63 type Unreify (AHNonEmpty context a) = HNonEmpty context (Unreify a)
65 fromColumns = sfromColumnsNonEmpty contextSing
66 toColumns = stoColumnsNonEmpty contextSing
68 smapNonEmpty contextSing (reify proof) hreify .
71 (\(AHNonEmpty a) -> a) .
72 smapNonEmpty contextSing (unreify proof) hunreify
76 ( Reifiable context, Reifiable context'
77 , Unreifiable (Reify context) a, Unreifiable (Reify context') a'
78 , Recontextualize (Reify context) (Reify context') a a'
83 (AHNonEmpty context a)
84 (AHNonEmpty context' a')
87smapNonEmpty :: Congruent a b
90 -> (HNonEmptyTable (Columns a) (Col (Context a)) -> HNonEmptyTable (Columns b) (Col (Context b)))
91 -> AHNonEmpty context a
92 -> AHNonEmpty context b
94 SAggregate -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
95 SExpr -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
96 SResult -> \f _ (AHNonEmpty as) -> AHNonEmpty (fmap f as)
97 SInsert -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
98 SName -> \_ f (AHNonEmpty (NonEmptyTable a)) -> AHNonEmpty (NonEmptyTable (f a))
99 SReify context -> \f g (AHNonEmpty as) -> AHNonEmpty (smapNonEmpty context f g as)
102sfromColumnsNonEmpty :: Table (Reify context) a
104 -> HNonEmptyTable (Columns a) (Col (Reify context))
105 -> AHNonEmpty context a
106sfromColumnsNonEmpty = \case
107 SAggregate -> AHNonEmpty . NonEmptyTable
108 SExpr -> AHNonEmpty . NonEmptyTable
110 AHNonEmpty . fmap (fromColumns . hreify) . fromColumns . hunreify
111 SInsert -> AHNonEmpty . NonEmptyTable
112 SName -> AHNonEmpty . NonEmptyTable
115 smapNonEmpty context (fromColumns . hreify) hreify .
116 sfromColumnsNonEmpty context .
120stoColumnsNonEmpty :: Table (Reify context) a
122 -> AHNonEmpty context a
123 -> HNonEmptyTable (Columns a) (Col (Reify context))
124stoColumnsNonEmpty = \case
125 SAggregate -> \(AHNonEmpty (NonEmptyTable a)) -> a
126 SExpr -> \(AHNonEmpty (NonEmptyTable a)) -> a
128 hreify . toColumns . fmap (hunreify . toColumns) . (\(AHNonEmpty a) -> a)
129 SInsert -> \(AHNonEmpty (NonEmptyTable a)) -> a
130 SName -> \(AHNonEmpty (NonEmptyTable a)) -> a
133 stoColumnsNonEmpty context .
134 smapNonEmpty context (hunreify . toColumns) hunreify .
135 (\(AHNonEmpty a) -> a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list