-
Notifications
You must be signed in to change notification settings - Fork 2
/
Keys.purs
30 lines (22 loc) 路 874 Bytes
/
Keys.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Record.Studio.Keys (class Keys, keys, class KeysRL, keysImpl, recordKeys) where
import Prelude
import Data.List (List, (:))
import Data.List as List
import Data.Symbol (class IsSymbol, reflectSymbol)
import Prim.RowList as RL
import Type.Proxy (Proxy(..))
class Keys (r :: Row Type) where
keys :: (Proxy r) -> Array String
instance (RL.RowToList r rl, KeysRL rl) => Keys r where
keys _ = List.toUnfoldable $ keysImpl (Proxy :: _ rl)
class KeysRL (xs :: RL.RowList Type) where
keysImpl :: Proxy xs -> List String
instance KeysRL RL.Nil where
keysImpl _ = mempty
instance (IsSymbol name, KeysRL tail) => KeysRL (RL.Cons name ty tail) where
keysImpl _ = first : rest
where
first = reflectSymbol (Proxy :: _ name)
rest = keysImpl (Proxy :: _ tail)
recordKeys :: forall r. Keys r => { | r } -> Array String
recordKeys _ = keys (Proxy :: _ r)