git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make 'compare on' example idiomatic
96b7f82Phil Freeman
prelude/README.md+4−5
@@ -252,7 +252,7 @@ types use the type constructor `f` to represent some computational context.
252(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
252(<#>) :: forall f a b. (Functor f) => f a -> (a -> b) -> f b
253```
253```
254
254
255−`(<#>)` is `(<$>)` with its arguments flipped. For example:
255+`(<#>)` is `(<$>)` with its arguments reversed. For example:
256
256
257```purescript
257```purescript
258[1, 2, 3] <#> \n -> n * n
258[1, 2, 3] <#> \n -> n * n
@@ -880,14 +880,13 @@ on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
880
880
881The `on` function is used to change the domain of a binary operator.
881The `on` function is used to change the domain of a binary operator.
882
882
883−For example, given a function `height :: Person -> Number`, we can create a function which compares two people by height:
883+For example, we can create a function which compares two records based on the values of their `x` properties:
884
884
885```purescript
885```purescript
886−taller :: Person -> Person -> Boolean
886+compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
887−taller = (>) `on` height
887+compareX = compare `on` _.x
888```
888```
889
889
890−
891#### `Fn0`
890#### `Fn0`
892
891
893``` purescript
892``` purescript
prelude/prelude.purs+4−5
@@ -234,7 +234,7 @@ module Prelude
234 class Functor f where
234 class Functor f where
235 (<$>) :: forall a b. (a -> b) -> f a -> f b
235 (<$>) :: forall a b. (a -> b) -> f a -> f b
236
236
237− -- | `(<#>)` is `(<$>)` with its arguments flipped. For example:
237+ -- | `(<#>)` is `(<$>)` with its arguments reversed. For example:
238 -- |
238 -- |
239 -- | ```purescript
239 -- | ```purescript
240 -- | [1, 2, 3] <#> \n -> n * n
240 -- | [1, 2, 3] <#> \n -> n * n
@@ -868,13 +868,12 @@ module Data.Function where
868
868
869 -- | The `on` function is used to change the domain of a binary operator.
869 -- | The `on` function is used to change the domain of a binary operator.
870 -- |
870 -- |
871− -- | For example, given a function `height :: Person -> Number`, we can create a function which compares two people by height:
871+ -- | For example, we can create a function which compares two records based on the values of their `x` properties:
872 -- |
872 -- |
873 -- | ```purescript
873 -- | ```purescript
874− -- | taller :: Person -> Person -> Boolean
874+ -- | compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
875− -- | taller = (>) `on` height
875+ -- | compareX = compare `on` _.x
876 -- | ```
876 -- | ```
877− -- |
878 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
877 on :: forall a b c. (b -> b -> c) -> (a -> b) -> a -> a -> c
879 on f g x y = g x `f` g y
878 on f g x y = g x `f` g y
880
879