-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSnapshot.Heterogeneous01.purs
47 lines (40 loc) · 1.12 KB
/
Snapshot.Heterogeneous01.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
-- @inline Heterogeneous.Mapping.hmapRecord arity=2
-- @inline Heterogeneous.Mapping.hmapWithIndexRecord arity=2
-- @inline Heterogeneous.Mapping.mapRecordWithIndexCons arity=5
-- @inline Heterogeneous.Mapping.mapRecordWithIndexNil.mapRecordWithIndexBuilder arity=2
module Snapshot.Heterogeneous01
( test1
, test2
) where
import Prelude
import Data.Symbol (class IsSymbol)
import Data.Tuple (Tuple(..))
import Heterogeneous.Mapping (hmap, hmapWithIndex, class MappingWithIndex)
import Prim.Row as Row
import Record as Record
import Record.Builder as Record.Builder
import Type.Proxy (Proxy(..))
newtype ZipProps fns = ZipProps { | fns }
instance zipProps ::
( IsSymbol sym
, Row.Cons sym (a -> b) x fns
) =>
MappingWithIndex (ZipProps fns) (Proxy sym) a b where
mappingWithIndex (ZipProps fns) prop = Record.get prop fns
zipRecord = hmapWithIndex <<< ZipProps
test1 =
{ a: add 1
, b: Tuple "bar"
, c: \a -> not a
}
`zipRecord`
{ a: 12
, b: 42.0
, c: true
}
test2 :: { a :: Int, b :: Number, c :: Boolean } -> _
test2 = zipRecord
{ a: add 1
, b: Tuple "bar"
, c: \a -> not a
}