Skip to content

Commit

Permalink
Add takeWhile and dropWhile
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelXavier committed Jan 24, 2015
1 parent 00ff8d2 commit f527161
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

drop :: forall a. Number -> [a] -> [a]

dropWhile :: forall a. (a -> Boolean) -> [a] -> [a]

elemIndex :: forall a. (Eq a) => a -> [a] -> Number

elemLastIndex :: forall a. (Eq a) => a -> [a] -> Number
Expand Down Expand Up @@ -107,6 +109,8 @@

take :: forall a. Number -> [a] -> [a]

takeWhile :: forall a. (a -> Boolean) -> [a] -> [a]

updateAt :: forall a. Number -> a -> [a] -> [a]

zipWith :: forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
Expand Down
8 changes: 8 additions & 0 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module Data.Array
, group'
, groupBy
, span
, dropWhile
, takeWhile
) where

import Control.Alt
Expand Down Expand Up @@ -354,6 +356,12 @@ span = go []
go acc p (x:xs) | p x = go (x:acc) p xs
go acc _ xs = { init: reverse acc, rest: xs }

takeWhile :: forall a. (a -> Boolean) -> [a] -> [a]
takeWhile p xs = (span p xs).init

dropWhile :: forall a. (a -> Boolean) -> [a] -> [a]
dropWhile p xs = (span p xs).rest

instance functorArray :: Functor [] where
(<$>) = map

Expand Down

0 comments on commit f527161

Please sign in to comment.