git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
47 lines 1.1 kB history raw
1-- @inline Heterogeneous.Mapping.hmapRecord arity=2
2-- @inline Heterogeneous.Mapping.hmapWithIndexRecord arity=2
3-- @inline Heterogeneous.Mapping.mapRecordWithIndexCons arity=5
4-- @inline Heterogeneous.Mapping.mapRecordWithIndexNil.mapRecordWithIndexBuilder arity=2
5module Snapshot.Heterogeneous01
6 ( test1
7 , test2
8 ) where
10import Prelude
12import Data.Symbol (class IsSymbol)
13import Data.Tuple (Tuple(..))
14import Heterogeneous.Mapping (hmap, hmapWithIndex, class MappingWithIndex)
15import Prim.Row as Row
16import Record as Record
17import Record.Builder as Record.Builder
18import Type.Proxy (Proxy(..))
20newtype ZipProps fns = ZipProps { | fns }
22instance zipProps ::
23 ( IsSymbol sym
24 , Row.Cons sym (a -> b) x fns
25 ) =>
26 MappingWithIndex (ZipProps fns) (Proxy sym) a b where
27 mappingWithIndex (ZipProps fns) prop = Record.get prop fns
29zipRecord = hmapWithIndex <<< ZipProps
31test1 =
32 { a: add 1
33 , b: Tuple "bar"
34 , c: \a -> not a
35 }
36 `zipRecord`
37 { a: 12
38 , b: 42.0
39 , c: true
40 }
42test2 :: { a :: Int, b :: Number, c :: Boolean } -> _
43test2 = zipRecord
44 { a: add 1
45 , b: Tuple "bar"
46 , c: \a -> not a
47 }