Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Set.Extra.any and Set.Extra.all #53

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions src/Set/Extra.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Set.Extra exposing
( toggle
, isSupersetOf, isSubsetOf, areDisjoint
, isSupersetOf, isSubsetOf, areDisjoint, any, all
, symmetricDifference
, concatMap, filterMap
)
Expand All @@ -15,7 +15,7 @@ module Set.Extra exposing

# Predicates

@docs isSupersetOf, isSubsetOf, areDisjoint
@docs isSupersetOf, isSubsetOf, areDisjoint, any, all


# Set operations
Expand Down Expand Up @@ -160,6 +160,44 @@ areDisjoint a b =
not (Set.foldl (\x so -> so || Set.member x b) False a)


{-| Determine if any elements satisfy some test.

import Set exposing (Set)

Set.Extra.any (\n -> modBy 2 n == 0) (Set.fromList [ 2, 3 ])
--> True

Set.Extra.any (\n -> modBy 2 n == 0) (Set.fromList [ 1, 3 ])
--> False

Set.Extra.any (\n -> modBy 2 n == 0) Set.empty
--> False

-}
any : (a -> Bool) -> Set a -> Bool
any isOkay set =
Set.foldl (\x acc -> acc || isOkay x) False set


{-| Determine if all elements satisfy some test.

import Set exposing (Set)

Set.Extra.all (\n -> modBy 2 n == 0) (Set.fromList [ 2, 4 ])
--> True

Set.Extra.all (\n -> modBy 2 n == 0) (Set.fromList [ 2, 3 ])
--> False

Set.Extra.all (\n -> modBy 2 n == 0) Set.empty
--> True

-}
all : (a -> Bool) -> Set a -> Bool
all isOkay set =
Set.foldl (\x acc -> acc && isOkay x) True set


{-| The symmetric difference between two sets is a set that contains all the elements that are in one of the two sets, but not both.

import Set exposing (Set)
Expand Down
Loading