ja-base-extra- Extra functions I require in base

Copyright(c) Justus Adam, 2015
PortabilityPOSIX, Windows
Safe HaskellSafe




Naming conventions for stuffing- and constant functions

If we follow trough with the naming conventions of stuffing- and constant functions the following rules emerge:

  stuffWith1 == const0 == id
  stuffWith0 == const1


Stuffing functions

Functions from the stuffing family are used when a function takes several consecutive arguments of the same type.

Sometimes it is desirable to call some of these arguments with the same value and those functions here allow you to do that in the "do-not-repeat-yourself" way.

The canonical way to call this function (if all arguments are present) would be in the infix form:

 function `stuffWith2` value

The naming convention is stuffWithN takes a function accepting at least N consecutive arguments of the same type and a value of that type calling the function with the provided value in all N places.

 stuff3 f a == f a a a

Multiple argument stuffing can also be achieved by chaining stuffWith.

 stuffWith4 f == (stuffWith . stuffWith . stuffWith) f

stuffWith :: (α -> α -> β) -> α -> β Source

Alias for stuffWith2

stuffWith2 :: (α -> α -> β) -> α -> β Source

stuffWith3 :: (α -> α -> α -> β) -> α -> β Source

stuffWith4 :: (α -> α -> α -> α -> β) -> α -> β Source

stuffWith5 :: (α -> α -> α -> α -> α -> β) -> α -> β Source

Constant functions

Functions from the const family behave very much like const function from prelude. But for more arguments.

The constN function takes a value and N arguments of arbitrary type returning the value unchanged after all arguments have been supplied.

The same effect can be reached by chaining const but does not look as good.

 const3 v == (const . const . const) v

const1 :: α -> β -> α Source

Alias for the const function from prelude in the const function family naming scheme.

const2 :: γ -> α -> β -> γ Source

const3 :: δ -> α -> β -> γ -> δ Source

const4 :: ε -> α -> β -> γ -> δ -> ε Source

const5 :: ζ -> α -> β -> γ -> δ -> ε -> ζ Source

Discard functions

Functions from the discard family behave opposite to functions from the const family.

Whereas constN will retin its first value and discard all N values, discardN wil discard the first N values, retaining the last one.

discard :: α -> β -> β Source

discard1 :: α -> β -> β Source

discard2 :: α -> β -> γ -> γ Source

discard3 :: α -> β -> γ -> δ -> δ Source

discard4 :: α -> β -> γ -> δ -> ε -> ε Source

discard5 :: α -> β -> γ -> δ -> ε -> ζ -> ζ Source