Last active
June 25, 2018 07:26
-
-
Save kuribas/cd0f725b9de6ff909326ad2856441943 to your computer and use it in GitHub Desktop.
all numbers in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import Data.Function | |
import Text.Read | |
import Data.Maybe | |
import Data.Char | |
all_numbers :: String -> [Int] | |
all_numbers = | |
mapMaybe (readMaybe :: String -> Maybe Int) . | |
groupBy ((==) `on` isDigit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun all-nums (s) | |
(mapcar #'parse-integer | |
(split-by s (complement #'digit-char-p)))) | |
(defun split-by (c f &key (start 0)) | |
(let* ((start2 (position-if-not f c :start start)) | |
(end (and start2 (position-if f c :start start2)))) | |
(and start2 | |
(cons (subseq c start2 end) | |
(and end | |
(split-by c f :start end)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment