/
FoldrValues.purs
69 lines (60 loc) · 1.82 KB
/
FoldrValues.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
module Record.ExtraSrghma.FoldrValues where
import Prelude
import Record (get) as Record
import Type.Prelude (class IsSymbol, Proxy(..))
import Type.Row.Homogeneous (class Homogeneous, class HomogeneousRowList)
import Prim.Row as Row
import Prim.RowList as RL
foldrValues
:: forall accum row fieldType rowList
. RL.RowToList row rowList
=> FoldrValues rowList row fieldType
=> (fieldType -> accum -> accum)
-> accum
-> Record row
-> accum
foldrValues = foldrValuesImpl (Proxy :: Proxy rowList)
foldMapValuesR
:: forall accum row fieldType rowList
. RL.RowToList row rowList
=> FoldrValues rowList row fieldType
=> Monoid accum
=> (fieldType -> accum)
-> Record row
-> accum
foldMapValuesR f = foldrValues (\x acc -> acc <> f x) mempty
class
( Homogeneous row fieldType
, HomogeneousRowList rowList fieldType
)
<= FoldrValues (rowList :: RL.RowList Type) (row :: Row Type) fieldType
| rowList -> row fieldType
where
foldrValuesImpl
:: forall accum
. Proxy rowList
-> (fieldType -> accum -> accum)
-> accum
-> Record row
-> accum
instance foldrValuesCons ::
( FoldrValues tailRowList row fieldType
, Homogeneous tailRow fieldType
, HomogeneousRowList tailRowList fieldType
, HomogeneousRowList trash fieldType
, IsSymbol name
, RL.RowToList row trash
, Row.Cons name fieldType tailRow row
) => FoldrValues (RL.Cons name fieldType tailRowList) row fieldType
where
foldrValuesImpl _ f accum record = f value $ foldrValuesImpl tailProxy f accum record
where
tailProxy :: Proxy tailRowList
tailProxy = Proxy
value :: fieldType
value = Record.get (Proxy :: Proxy name) record
instance foldrValuesNil
:: Homogeneous row fieldType
=> FoldrValues RL.Nil row fieldType
where
foldrValuesImpl _ _ accum _ = accum