Skip to content

Commit

Permalink
Making identity,const,flip,curry,uncurry member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jun 29, 2022
1 parent 84c4110 commit 0a8cdbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
- [Removed obsolete `from_xls` and `from_xlsx` functions. Added support for
reading column names from first row in `File_Format.Excel`][3523]
- [Added `File_Format.Delimited` support to `Table.write` for new files.][3528]
- [identity,const,flip,curry,uncurry functions][3554]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -227,6 +228,7 @@
[3519]: https://github.com/enso-org/enso/pull/3519
[3523]: https://github.com/enso-org/enso/pull/3523
[3528]: https://github.com/enso-org/enso/pull/3528
[3554]: https://github.com/enso-org/enso/pull/3554

#### Enso Compiler

Expand Down
20 changes: 10 additions & 10 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Function.enso
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Function
> Example
five = Function.identity 5 # returns number 5

Function.identity : a -> a
Function.identity x = x
identity : a -> a
identity x = x

## Flips the first two arguments of a function. Returns function that
takes two arguments, but in opposite order.
Expand All @@ -31,8 +31,8 @@ Function.identity x = x
> Example
Console.log <| Function.flip (+) "world" "hello" # Prints 'helloworld'

Function.flip : (a -> b -> c) -> (b -> a -> c)
Function.flip f = (x -> y -> f y x)
flip : (a -> b -> c) -> (b -> a -> c)
flip f = (x -> y -> f y x)


## Creates a function which drops its input and returns the provided value instead.
Expand All @@ -44,21 +44,21 @@ Function.flip f = (x -> y -> f y x)
> Example
Console.log <| [1, 2, 3].map (Function.const 7) # Prints '[7, 7, 7]'

Function.const : a -> b -> a
Function.const x _ = x
const : a -> b -> a
const x _ = x

## Converts a single-argument function accepting a pair of elements into a multi-argument one.

Arguments:
- f function accepting pair of values

Function.curry : ([a, b] -> c) -> (a -> b -> c)
Function.curry f = x -> y -> f [x, y]
curry : ([a, b] -> c) -> (a -> b -> c)
curry f = x -> y -> f [x, y]

## Converts a multi-argument function into a single-argument one accepting a pair of elements.

Arguments:
- f function accepting multiple arguments

Function.uncurry : (a -> b -> c) -> ([a, b] -> c)
Function.uncurry f = (pair -> f pair.head pair.tail.head)
uncurry : (a -> b -> c) -> ([a, b] -> c)
uncurry f = (pair -> f pair.head pair.tail.head)
1 change: 1 addition & 0 deletions test/Tests/src/Data/Function_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Standard.Base import all
import Standard.Base.Data.Numbers
import Standard.Base.Function

import Standard.Test
from Standard.Base.Data.Ordering import Equal, Less, Greater
Expand Down

0 comments on commit 0a8cdbe

Please sign in to comment.