Permalink
Browse files

Added partial set/modify versions that act as identity when the const…

…ructor field is not available.
  • Loading branch information...
1 parent ea40645 commit 888e39ddccfdab4667f812829a9f17840034f761 @sebastiaanvisser committed Apr 29, 2012
Showing with 23 additions and 4 deletions.
  1. +4 −0 CHANGELOG
  2. 0 LICENCE → LICENSE
  3. +5 −4 fclabels.cabal
  4. +14 −0 src/Data/Label/Maybe.hs
View
@@ -1,5 +1,9 @@
CHANGELOG
+ 1.1.1.0 -> 1.1.2
+ - Added partial set/modify versions that act as identity when the
+ constructor field is not available.
+
1.1.1.0 -> 1.1.1.1
- Relax dependency on transformers to include 0.3.0.0.
View
File renamed without changes.
View
@@ -1,5 +1,5 @@
Name: fclabels
-Version: 1.1.1.1
+Version: 1.1.2
Author: Sebastiaan Visser, Erik Hesselink, Chris Eidhof, Sjoerd Visscher
with lots of help and feedback from others.
Synopsis: First class accessor labels.
@@ -20,12 +20,13 @@ Description: This package provides first class labels that can act as
.
See the "Data.Label.Maybe" module for the use of partial labels.
.
- > 1.1.1.0 -> 1.1.1.1
- > - Relax dependency on transformers to include 0.3.0.0.
+ > 1.1.1.0 -> 1.1.2
+ > - Added partial set/modify versions that act as identity
+ > when the constructor field is not available.
Maintainer: Sebastiaan Visser <code@fvisser.nl>
License: BSD3
-License-File: LICENCE
+License-File: LICENSE
Category: Data
Cabal-Version: >= 1.6
Build-Type: Simple
View
@@ -4,7 +4,9 @@ module Data.Label.Maybe
, lens
, get
, set
+, set'
, modify
+, modify'
, embed
)
where
@@ -47,12 +49,24 @@ get l = run (A.get l)
set :: f :~> a -> a -> f -> Maybe f
set l v = run (A.set l . arr (v,))
+-- | Like 'set' but return behaves like the identity function when the field
+-- could not be set.
+
+set' :: (f :~> a) -> a -> f -> f
+set' l v f = f `fromMaybe` set l v f
+
-- | Modifier for a lens that can fail. When the field to which the lens points
-- is not accessible this function returns 'Nothing'.
modify :: (f :~> a) -> (a -> a) -> f -> Maybe f
modify l m = run (A.modify l . arr (arr m,))
+-- | Like 'modify' but return behaves like the identity function when the field
+-- could not be set.
+
+modify' :: (f :~> a) -> (a -> a) -> f -> f
+modify' l m f = f `fromMaybe` modify l m f
+
-- | Embed a pure lens that points to a `Maybe` field into a lens that might
-- fail.

0 comments on commit 888e39d

Please sign in to comment.