Hello community,

here is the log from the commit of package ghc-optional-args for 
openSUSE:Factory checked in at 2016-04-22 16:25:10
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-optional-args (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-optional-args.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-optional-args"

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-optional-args/ghc-optional-args.changes      
2016-02-09 13:32:06.000000000 +0100
+++ /work/SRC/openSUSE:Factory/.ghc-optional-args.new/ghc-optional-args.changes 
2016-04-22 16:25:28.000000000 +0200
@@ -1,0 +2,5 @@
+Sun Apr 17 15:11:40 UTC 2016 - [email protected]
+
+- update to 1.0.1
+
+-------------------------------------------------------------------

Old:
----
  optional-args-1.0.0.tar.gz

New:
----
  optional-args-1.0.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-optional-args.spec ++++++
--- /var/tmp/diff_new_pack.olEcl6/_old  2016-04-22 16:25:28.000000000 +0200
+++ /var/tmp/diff_new_pack.olEcl6/_new  2016-04-22 16:25:28.000000000 +0200
@@ -18,7 +18,7 @@
 %global pkg_name optional-args
 
 Name:           ghc-optional-args
-Version:        1.0.0
+Version:        1.0.1
 Release:        0
 Summary:        Optional function arguments
 Group:          System/Libraries

++++++ optional-args-1.0.0.tar.gz -> optional-args-1.0.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/optional-args-1.0.0/optional-args.cabal 
new/optional-args-1.0.1/optional-args.cabal
--- old/optional-args-1.0.0/optional-args.cabal 2015-06-15 04:24:32.000000000 
+0200
+++ new/optional-args-1.0.1/optional-args.cabal 2016-04-16 06:11:46.000000000 
+0200
@@ -1,5 +1,5 @@
 Name: optional-args
-Version: 1.0.0
+Version: 1.0.1
 Cabal-Version: >=1.10
 Build-Type: Simple
 License: BSD3
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/optional-args-1.0.0/src/Data/Optional.hs 
new/optional-args-1.0.1/src/Data/Optional.hs
--- old/optional-args-1.0.0/src/Data/Optional.hs        2015-06-15 
04:24:32.000000000 +0200
+++ new/optional-args-1.0.1/src/Data/Optional.hs        2016-04-16 
06:11:21.000000000 +0200
@@ -3,78 +3,78 @@
 {-# LANGUAGE DeriveTraversable #-}
 
 -- | Use the `Optional` type for optional function arguments.  For example:
--- 
+--
 -- > import Data.Optional
 -- >
 -- > greet :: Optional String -> String
 -- > greet (Specific name) = "Hello, " ++ name
 -- > greet  Default        = "Hello"
--- 
+--
 -- >>> greet (Specific "John")
 -- "Hello, John"
 -- >>> greet Default
 -- "Hello"
--- 
+--
 --     The `Optional` type overloads as many Haskell literals as possible so
 --     that you do not need to wrap values in `Specific`.  For example, if you
 --     enable the `OverloadedStrings` extension you can use a naked string
 --     literal instead:
--- 
+--
 -- >>> :set -XOverloadedStrings
 -- >>> greet "John"
 -- "Hello, John"
--- 
+--
 --     The `Optional` type also implements `Num` and `Fractional`, so you can
 --     use numeric literals in place of `Optional` values:
--- 
+--
 -- > birthday :: Optional Int -> String
 -- > birthday (Specific age) = "You are " ++ show age ++ " years old!"
 -- > birthday  Default       = "You are one year older!"
--- 
+--
 -- >>> birthday 20
 -- "You are 20 years old!"
 -- >>> birthday Default
 -- "You are one year older!"
--- 
+--
 --     The `IsString`, `Num`, and `Fractional` instances are recursive, so you
 --     can wrap your types in a more descriptive newtype and derive `IsString`,
 --     `Num` or `Fractional`:
--- 
+--
 -- > {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--- > 
+-- >
 -- > import Data.Optional
 -- > import Data.String (IsString)
--- > 
+-- >
 -- > newtype Name = Name { getName :: String } deriving (IsString)
--- > 
+-- >
 -- > greet :: Optional Name -> String
 -- > greet (Specific name) = "Hello, " ++ getName name
 -- > greet  Default        = "Hello"
--- > 
+-- >
 -- > newtype Age = Age { getAge :: Int } deriving (Num)
--- > 
+-- >
 -- > birthday :: Optional Age -> String
 -- > birthday (Specific age) = "You are " ++ show (getAge age) ++ " years old!"
 -- > birthday  Default       = "You are one year older!"
--- 
+--
 --     ... and you would still be able to provide naked numeric or string
 --     literals:
--- 
+--
 -- >>> :set -XOverloadedStrings
 -- >>> greet "John"
 -- "Hello, John"
 -- >>> birthday 20
 -- "You are 20 years old!"
--- 
+--
 --     You can use `empty` as a short-hand for a `Default` argument:
--- 
+--
 -- >>> greet empty
 -- "Hello"
 -- >>> birthday empty
 -- "You are one year older!"
--- 
+--
 --     You can also use `pure` as a short-hand for a `Specific` argument:
--- 
+--
 -- >>> greet (pure "John")
 -- "Hello, John"
 -- >>> birthday (pure 20)
@@ -83,6 +83,9 @@
 module Data.Optional (
     -- * Optional
       Optional(..)
+    , defaultTo
+    , fromOptional
+    , optional
 
     -- * Re-exports
     , empty
@@ -147,3 +150,23 @@
     recip = fmap recip
 
     (/) = liftA2 (/)
+
+-- | The 'optional' function takes a default value, a function, and an
+-- 'Optional' value. If the 'Optional' value is 'Default', the function returns
+-- the default value. Otherwise, it applies the function to the value inside 
the
+-- 'Optional' and returns the result.
+optional :: b -> (a -> b) -> Optional a -> b
+optional n _ Default      = n
+optional _ f (Specific x) = f x
+
+-- | The 'defaultTo' function takes a default value and an 'Optional'
+-- value.  If the 'Optional' is 'Default', it returns the default value;
+-- otherwise, it returns the value contained in the 'Optional'.
+defaultTo :: a -> Optional a -> a
+defaultTo d Default      = d
+defaultTo _ (Specific v) = v
+
+-- | Convert an 'Optional' value into an instance of 'Alternative'.
+fromOptional :: Alternative f => Optional a -> f a
+fromOptional  Default     = empty
+fromOptional (Specific x) = pure x


Reply via email to