Idris2/tests/base/data_list002/Prefix.idr
Jan de Muijnck-Hughes 4ba3bb6670
[ fix ] Literate things (#2312)
Co-authored-by: G. Allais <guillaume.allais@ens-lyon.org>
2022-02-18 11:29:52 +00:00

20 lines
656 B
Idris

import Data.List
import Data.String
byLength : Nat -> String -> Maybe (String, Nat)
byLength n str = (str, n) <$ guard (String.length str == n)
bySuccess : a -> (a -> Maybe b) -> Maybe b
bySuccess = flip ($)
-- cheating to display the remaining (const Nothing) function in 3rd case
Show b => Show (List a -> b) where
show f = "\\ _ => " ++ show (f [])
main : IO ()
main = putStr $ unlines
[ show $ prefixOfBy byLength [5,5,1] ["hello", "world", "!", "Not", "seen"]
, show $ suffixOfBy byLength [3,4] ["hello", "world", "!", "Not", "seen"]
, show $ prefixOfBy bySuccess [[1],[1,2],[]] [head', head' <=< tail', const (pure 3), const Nothing]
]