Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Forked from mkscrg/Main.hs
Last active December 23, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puffnfresh/6654350 to your computer and use it in GitHub Desktop.
Save puffnfresh/6654350 to your computer and use it in GitHub Desktop.
module Main where
import Data.List (inits)
import Data.List.Split (splitOn)
main :: IO ()
main = print $ wordIndexes "Hello test World"
wordIndexes :: String -> [(Int, String)]
wordIndexes s =
let splitted = splitOn " " s
index [] = 0
index xs = length (unwords xs) + 1
in filter (not . null . snd) $ zip (fmap index $ inits splitted) splitted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment