packages feed

extism-pdk-0.1.0.0: examples/CountVowels.hs

module CountVowels where

import Extism.PDK
import Extism.PDK.JSON

isVowel c = 
  c == 'a' || c == 'A' ||
  c == 'e' || c == 'E' ||
  c == 'i' || c == 'I' ||
  c == 'o' || c == 'O' ||
  c == 'u' || c == 'U'

countVowels = do
  -- Get input string from Extism host
  s <- input
  -- Calculate the number of vowels
  let count = length (filter isVowel s)
  -- Return a JSON object {"count": count} back to the host
  output $ JSONValue $ object ["count" .= count]

foreign export ccall "count_vowels" countVowels ::  IO ()