Move stuff around + add lean and idris experiments
This commit is contained in:
parent
a45a4e94b3
commit
ca3f83d186
122 changed files with 1959 additions and 2 deletions
purescript/ecs/src/Utils
40
purescript/ecs/src/Utils/Keys.purs
Normal file
40
purescript/ecs/src/Utils/Keys.purs
Normal file
|
@ -0,0 +1,40 @@
|
|||
-- | Modified version of the code from [record-extra](https://github.com/justinwoo/purescript-record-extra/blob/v4.0.0/src/Record/Extra.purs#L123-L127)
|
||||
-- | I did not like how that lib used lists, so I modified it to output to an (initially) mutable array
|
||||
module Thing.Ecs.Utils.Keys (keys, class Keys, keysImpl) where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.ST (ST)
|
||||
import Data.Array.ST (STArray)
|
||||
import Data.Array.ST as STArray
|
||||
import Data.Symbol (class IsSymbol, reflectSymbol)
|
||||
import Prim.RowList as RL
|
||||
import Type.Proxy (Proxy(..))
|
||||
|
||||
-- | Typeclass jk
|
||||
class Keys (xs :: RL.RowList Type) where
|
||||
keysImpl :: forall r. Proxy xs -> ST r (STArray r String)
|
||||
|
||||
instance Keys RL.Nil where
|
||||
keysImpl _ = STArray.empty
|
||||
|
||||
instance
|
||||
( IsSymbol name
|
||||
, Keys tail
|
||||
) =>
|
||||
Keys (RL.Cons name ty tail) where
|
||||
keysImpl _ = do
|
||||
rest <- keysImpl (Proxy :: _ tail)
|
||||
_ <- STArray.push first rest
|
||||
pure rest
|
||||
where
|
||||
first = reflectSymbol (Proxy :: _ name)
|
||||
|
||||
-- | Extract a value level array of the keys of a row
|
||||
keys
|
||||
:: forall g row rl
|
||||
. RL.RowToList row rl
|
||||
=> Keys rl
|
||||
=> g row -- this will work for any type with the row as a param!
|
||||
-> Array String
|
||||
keys _ = STArray.run (keysImpl (Proxy :: _ rl))
|
Loading…
Add table
Add a link
Reference in a new issue