optics-core-0.2: Optics as an abstract interface: core definitions

Data.Set.Optics

Description

This module defines optics for constructing and manipulating finite Sets.

Set

setmapped :: Ord b => Setter (Set a) (Set b) a b Source #

This Setter can be used to change the type of a Set by mapping the elements to new values.

Setter

Sadly, you can't create a valid Traversal for a Set, but you can manipulate it by reading using folded and reindexing it via setmapped.

Traversal

folded

setmapped

>>> over setmapped (+1) (fromList [1,2,3,4]) fromList [2,3,4,5]

>>>

over setmapped (+1) (fromList [1,2,3,4])

setOf :: (Is k A_Fold, Ord a) => Optic' k is s a -> s -> Set a Source #

Construct a set from a fold.

>>> setOf folded ["hello","world"] fromList ["hello","world"]

setOf folded ["hello","world"]

>>> setOf (folded % _2) [("hello",1),("world",2),("!!!",3)] fromList [1,2,3]

setOf (folded % _2) [("hello",1),("world",2),("!!!",3)]