Created
July 16, 2024 16:26
-
-
Save imsaravana369/bbc01f20bef24b6f4f97a365c6bb0410 to your computer and use it in GitHub Desktop.
Given a dot-separated Symbol, the typeclass `SplitOnPeriodWrap` will give the last segment of the dot separated symbol.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Split where | |
import Prelude | |
import Data.Foldable (fold) | |
import Effect (Effect) | |
import Effect.Console(log) | |
import Effect.Unsafe | |
import Type.Proxy | |
import Prim.Symbol as Symbol | |
import Data.Symbol(class IsSymbol) | |
import Type.Data.Symbol | |
import Prim.Boolean | |
class SplitOnPeriod (h :: Symbol) (t :: Symbol) (acc :: Symbol) (last :: Symbol) | h t -> last | |
-- instance SplitOnPeriod "." t acc acc t | |
instance | |
(Symbol.Append acc h accPlus) | |
=> SplitOnPeriod h "" acc accPlus | |
else instance ( Symbol.Cons h t tail | |
, SplitOnPeriod h t "" last | |
) => SplitOnPeriod "." tail acc last | |
else instance | |
( | |
Symbol.Cons h t tail, | |
Symbol.Append acc head accPlus, | |
SplitOnPeriod h t accPlus last | |
) => | |
SplitOnPeriod head tail acc last | |
class SplitOnPeriodWrap (inp :: Symbol) (last :: Symbol) | inp -> last | |
instance | |
( | |
Cons h t inp, | |
SplitOnPeriod h t "" last | |
) => | |
SplitOnPeriodWrap inp last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment