Skip to content

Instantly share code, notes, and snippets.

@LATBauerdick
LATBauerdick / strings-codeunits.cpp
Last active January 31, 2019 16:09
example code for purescript-native ffi code, using a purescript call-back function
// foreign import countPrefix :: (Char -> Boolean) -> String -> Int
//
exports["countPrefix"] = [](const boxed& f_) -> boxed {
return [=](const boxed& s_) -> boxed {
const string& s = unbox<string>(s_);
size_t i = 0;
while ( i<s.length() && unbox<bool>(f_(boxed(s.substr(i, 1)))) ) i++;
return i;
};
};