Skip to content

Commit

Permalink
Add the always function
Browse files Browse the repository at this point in the history
I want it, I do not want to rename constant, and I think it is a good
name.
  • Loading branch information
process-bot committed Jan 17, 2014
1 parent 996848c commit 6a38282
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion libraries/Basics.elm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ which happen to be radians.
@docs fst, snd
# Higher-Order Helpers
@docs id, (<|), (|>), (.), flip, curry, uncurry
@docs id, (<|), (|>), (.), always, flip, curry, uncurry
-}

Expand Down Expand Up @@ -313,6 +313,22 @@ infixl 0 |>
id : a -> a
id x = x

{-| Creates a [constant function](http://en.wikipedia.org/wiki/Constant_function),
a function that *always* returns the same value regardless of what input you give.
It is defined simply as:
always a b = a
It totally ignores the second argument, so `always 42` is a function that always
returns in 42. When you are dealing with higher-order functions, this comes in
handy more often than you might expect. For example, creating a zeroed out list
of length ten would be:
map (always 0) [0..9]
-}
always : a -> b -> a
always a _ = a

{-| Given a 2-tuple, returns the first value. -}
fst : (a,b) -> a
fst (a,_) = a
Expand Down

0 comments on commit 6a38282

Please sign in to comment.