justinwoo / purescript-sijidou

A library for matching a string into a record of functions of statically known Symbol proxies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PureScript-Sijidou

A library for matching a string into a record of functions of statically known Symbol proxies.

Named after 干煸四季豆 (gan bian sijidou), aka what people call "that string bean dish I tried once in a weird Chinese restaurant".

Example

main = do
  let
    fruits =
      { apple: "great"
      , banana: "good"
      }

    key1 = "apple"
    key2 = "durian"
    key3 = "banana"

    matchString :: String -> Maybe String
    matchString = S.matchString
      { apple: \k -> Record.get k fruits
      , banana: \k -> Record.get k fruits
      }

    result1 = matchString key1
    result2 = matchString key2
    result3 = matchString key3

  assertEqual { actual: result1, expected: Just "great" }
  assertEqual { actual: result2, expected: Nothing }
  assertEqual { actual: result3, expected: Just "good" }

About

A library for matching a string into a record of functions of statically known Symbol proxies.

License:MIT License


Languages

Language:PureScript 100.0%