String matching: Difference between revisions

m
(→‎{{header|AppleScript}}: Added a functionally composed variant (defining offsets in terms of findindices))
Line 197:
 
or, defining an '''offsets''' function in terms of a more general '''findIndices''':
<lang applescript>-- offsets :: String -> String -> [Int]
-- offsets :: String -> String -> [Int]
on offsets(needle, haystack)
script match
property mx : length of haystack
property lngd : (length of needle) - 1
on |λ|(x, i, xs)
if mx ≥ lngd + i then
needle = (text i thru (id + (lng - 1)i) of xs)
else
false
Line 211 ⟶ 210:
end |λ|
end script
 
findIndices(match, haystack)
end offsets
9,659

edits