Skip to content

Commit

Permalink
Bump to v0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinitto committed Feb 9, 2023
1 parent 66ff540 commit ae30538
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.3.3] - 2023-02-09

### Added

- Add ability to curry functions i.e. transform functions with multiple args into functions with fewer args

### Changed

### Fixed

## [0.3.2] - 2023-02-08

### Added
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ def main():
unit = ml.val(lambda v: v)
is_even = ml.val(lambda v: v % 2 == 0)
mul = ml.val(lambda args: args[0] * args[1])
superscript = ml.val(lambda num, power: num**power)
superscript = ml.val(lambda num, power=1: num**power)
get_month = ml.val(lambda value: value.month)
is_num = ml.val(lambda v: isinstance(v, (int, float)))
is_exp = ml.val(lambda v: isinstance(v, BaseException))
is_zero_or_less = ml.val(lambda v, *args: v <= 0)
if_else = lambda check=unit, do=unit, else_do=unit: ml.val(
lambda *args, **kwargs: (
ml.match(check(*args, **kwargs))
Expand All @@ -97,13 +96,13 @@ def main():
"""
High Order Expressions
"""
accum_factorial = if_else(
check=is_zero_or_less,
do=lambda v, ac: ac,
else_do=lambda v, ac: accum_factorial(v - 1, v * ac),
factorial = lambda v, accum=1: (
ml.match(v <= 0)
.case(True, do=ml.val(accum))
.case(False, do=lambda num, ac=0: factorial(num - 1, accum=num * ac)())
)
cube = ml.val(lambda v: superscript(v, 3))
factorial = ml.val(lambda x: accum_factorial(x, 1))
# currying expressions is possible
cube = superscript(power=3)
get_item_types = ml.ireduce(lambda x, y: f"{type(x)}, {type(y)}")
nums_type_err = ml.val(
lambda args: TypeError(f"expected numbers, got {get_item_types(args)}")
Expand Down
9 changes: 9 additions & 0 deletions docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.3.3] - 2023-02-09

### Added

- Add ability to curry functions i.e. transform functions with multiple args into functions with fewer args

### Changed

### Fixed

## [0.3.2] - 2023-02-08

Expand Down
16 changes: 8 additions & 8 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ def main():
unit = ml.val(lambda v: v)
is_even = ml.val(lambda v: v % 2 == 0)
mul = ml.val(lambda args: args[0] * args[1])
superscript = ml.val(lambda num, power: num**power)
superscript = ml.val(lambda num, power=1: num**power)
get_month = ml.val(lambda value: value.month)
is_num = ml.val(lambda v: isinstance(v, (int, float)))
is_exp = ml.val(lambda v: isinstance(v, BaseException))
is_zero_or_less = ml.val(lambda v, *args: v <= 0)
if_else = lambda check=unit, do=unit, else_do=unit: ml.val(
lambda *args, **kwargs: (
ml.match(check(*args, **kwargs))
Expand All @@ -143,6 +142,7 @@ def main():
Here we combine the primitive expressions into more complex ones using:

- normal function calls e.g. `if_else(some_stuff)` where `if_else` is a primitive expression
- a form of [currying](https://en.wikipedia.org/wiki/Currying) e.g. `add3 = add(3)` where `add = lambda x, y: x+y`
- pipelines using the pipeline operator (`>>`).
Pipelines let one start with data followed by the steps that operate on that
data e.g. `output = records >> remove_nulls >> parse_json >> ml.execute()`
Expand All @@ -161,13 +161,13 @@ In our `main` function in our script `main.py`, let's add the following high ord
"""
High Order Expressions
"""
accum_factorial = if_else(
check=is_zero_or_less,
do=lambda v, ac: ac,
else_do=lambda v, ac: accum_factorial(v - 1, v * ac),
factorial = lambda v, accum=1: (
ml.match(v <= 0)
.case(True, do=ml.val(accum))
.case(False, do=lambda num, ac=0: factorial(num - 1, accum=num * ac)())
)
cube = ml.val(lambda v: superscript(v, 3))
factorial = ml.val(lambda x: accum_factorial(x, 1))
# currying expressions is possible
cube = superscript(power=3)
get_item_types = ml.ireduce(lambda x, y: f"{type(x)}, {type(y)}")
nums_type_err = ml.val(
lambda args: TypeError(f"expected numbers, got {get_item_types(args)}")
Expand Down
15 changes: 7 additions & 8 deletions docs_src/tutorial/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ def main():
unit = ml.val(lambda v: v)
is_even = ml.val(lambda v: v % 2 == 0)
mul = ml.val(lambda args: args[0] * args[1])
superscript = ml.val(lambda num, power: num**power)
superscript = ml.val(lambda num, power=1: num**power)
get_month = ml.val(lambda value: value.month)
is_num = ml.val(lambda v: isinstance(v, (int, float)))
is_exp = ml.val(lambda v: isinstance(v, BaseException))
is_zero_or_less = ml.val(lambda v, *args: v <= 0)
if_else = lambda check=unit, do=unit, else_do=unit: ml.val(
lambda *args, **kwargs: (
ml.match(check(*args, **kwargs))
Expand All @@ -52,13 +51,13 @@ def main():
"""
High Order Expressions
"""
accum_factorial = if_else(
check=is_zero_or_less,
do=lambda v, ac: ac,
else_do=lambda v, ac: accum_factorial(v - 1, v * ac),
factorial = lambda v, accum=1: (
ml.match(v <= 0)
.case(True, do=ml.val(accum))
.case(False, do=lambda num, ac=0: factorial(num - 1, accum=num * ac)())
)
cube = ml.val(lambda v: superscript(v, 3))
factorial = ml.val(lambda x: accum_factorial(x, 1))
# currying expressions is possible
cube = superscript(power=3)
get_item_types = ml.ireduce(lambda x, y: f"{type(x)}, {type(y)}")
nums_type_err = ml.val(
lambda args: TypeError(f"expected numbers, got {get_item_types(args)}")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "funml"
version = "0.3.2"
version = "0.3.3"
description = "A collection of utilities to help write python as though it were an ML-kind of functional language like OCaml"
authors = ["Martin <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit ae30538

Please sign in to comment.