Skip to content

Commit

Permalink
0.2 (#2)
Browse files Browse the repository at this point in the history
* Adds common interface for fixed functions
* New NFix type
  • Loading branch information
Tokazama authored Jun 6, 2020
1 parent 39e9725 commit d0b68ab
Show file tree
Hide file tree
Showing 9 changed files with 473 additions and 68 deletions.
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
language: julia
os:
- linux
- osx
- osx
- linux
julia:
- 1.3
- nightly
- 1.3
- nightly

codecov: true

matrix:
allow_failures:
- julia: nightly
fast_finish: true

notifications:
email: false
email: false

jobs:
include:
- stage: "Documentation"
julia: 1.3
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/ docs/make.jl
after_success: skip

after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ChainedFixes"
uuid = "9706b775-b1f4-4c74-b677-0491368ea71c"
authors = ["Zachary P. Christensen <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[compat]
julia = "1"
Expand Down
117 changes: 82 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,108 @@
# ChainedFixes

[![Build Status](https://travis-ci.com/Tokazama/ChainedFixes.jl.svg?branch=master)](https://travis-ci.com/Tokazama/ChainedFixes.jl) [![codecov](https://codecov.io/gh/Tokazama/ChainedFixes.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/Tokazama/ChainedFixes.jl)
[![stable-docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://Tokazama.github.io/ChainedFixes.jl/stable)
[![dev-docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://Tokazama.github.io/ChainedFixes.jl/dev)

Chain operators `Base.Fix2` operations with two possible methods.

`and` is synonymous with bitwise `&` operator but may be used to chain multiple `Fix1` or
`Fix2` operations. The `` (`\\And<TAB>`) operator may be used in its place (e.g., `x ⩓ y`).
`ChainedFixes.jl` provides useful tools for interacting with functions where arguments are fixed to them.
This includes support for those found in Julia's `Base` module (`Base.Fix1`, `Base.Fix2`) and exported from `ChainedFixes` (`ChainedFix` and `NFix`).

Some simple functionality available form this package is chaining any fixed function.
```julia
julia> using ChainedFixes

julia> and(true, <(5))(1)
julia> gt_or_lt = or(>(10), <(5));

julia> gt_or_lt(2)
true

julia> and(<(5), false)(1)
julia> gt_or_lt(6)
false

julia> and(and(<(5), >(1)), >(2))(3)
true

julia> and(<(5) >(1), >(2))(3) # ⩓ == \\And
julia> gt_and_lt = and(>(1), <(5));

julia> gt_and_lt(2)
true

julia> gt_and_lt(0)
false
```

`or` is synonymous with bitwise `|` operator but may be used to chain multiple `Fix1` or
`Fix2` operations. The `` (`\\Or<TAB>`) operator may be used in its place (e.g., `x ⩔ y`).

There's more convenient syntax for these available in the Julia REPL.
```julia
julia> using ChainedFixes
julia> gt_or_lt = >(10) <(5); # \Or<TAB>

julia> or(true, <(5))(1)
julia> gt_or_lt(2)
true

julia> or(<(5), false)(1)
true
julia> gt_or_lt(6)
false


julia> or(<(5) >(1), >(2))(3) # ⩔ == \\Or
julia> gt_and_lt = >(1) <(5); # \And<TAB>

julia> gt_and_lt(2)
true

julia> gt_and_lt(0)
false
```

Any function can have methods fixed to it with the `NFix` function.

```julia
julia> fxn1(x::Integer, y::AbstractFloat, z::AbstractString) = Val(1);

julia> fxn1(x::Integer, y::AbstractString, z::AbstractFloat) = Val(2);

julia> fxn1(x::AbstractFloat, y::Integer, z::AbstractString) = Val(3);

julia> fxn2(; x, y, z) = fxn1(x, y, z);

julia> fxn3(args...; kwargs...) = (fxn1(args...), fxn2(; kwargs...));

julia> NFix{(1,2)}(fxn1, 1, 2.0)("a")
Val{1}()

julia> NFix{(1,3)}(fxn1, 1, 2.0)("a")
Val{2}()

julia> NFix{(1,3)}(fxn1, 1.0, "")(2)
Val{3}()

julia> NFix(fxn2, x=1, y=2.0)(z = "a")
Val{1}()

julia> NFix(fxn2, x=1, z=2.0)(y="a")
Val{2}()

julia> NFix{(1,2)}(fxn3, 1, 2.0; x=1.0, z="")(""; y = 1)
(Val{1}(), Val{3}())

```

## Conveniant Type Constants

| Syntax | Type Constant |
| -----------: | ----------------------- |
| `and`/`` | `And{F1,F2}` |
| `or`/`` | `Or{F1,F2}` |
| `isapprox` | `Approx{T,Kwargs}` |
| `in` | `In{T}` |
| `!in` | `NotIn{T}` |
| `<` | `Less{T}` |
| `<=` | `LessThanOrEqual{T}` |
| `>` | `Greater{T}` |
| `>=` | `GreaterThanOrEqual{T}` |
| `==` | `Equal{T}` |
| `isequal` | `Equal{T}` |
| `!=` | `NotEqual{T}` |
| `startswith` | `StartsWith{T}` |
| `endswith` | `EndsWith{T}` |

## Constants

The following constants are exported.

| Syntax | Type Constant |
|------------------------------------------:|:------------------------|
| `and(f1::F1, f1::F2)`/`⩓(f1::F1, f1::F2)` | `And{F1,F2}` |
| `or(f1::F1, f1::F2)`/`⩔(f1::F1, f1::F2)` | `Or{F1,F2}` |
| `isapprox(x::T; kwargs::Kwargs)` | `Approx{T,Kwargs}` |
| `!isapprox(x::T; kwargs::Kwargs)` | `NotApprox{T,Kwargs}` |
| `in(x::T)` | `In{T}` |
| `!in(x::T)` | `NotIn{T}` |
| `<(x::T)` | `Less{T}` |
| `<=(x::T)` | `LessThanOrEqual{T}` |
| `>(x::T)` | `Greater{T}` |
| `>=(x::T)` | `GreaterThanOrEqual{T}` |
| `==(x::T)` | `Equal{T}` |
| `isequal(x::T)` | `Equal{T}` |
| `!=(x::T)` | `NotEqual{T}` |
| `startswith(x::T)` | `StartsWith{T}` |
| `endswith(x::T)` | `EndsWith{T}` |


2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
16 changes: 16 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Documenter, ChainedFixes

makedocs(;
modules=[ChainedFixes],
format=Documenter.HTML(),
pages=[
"ChainedFixes" => "index.md",
],
repo="https://github.com/Tokazma/ChainedFixes.jl/blob/{commit}{path}#L{line}",
sitename="ChainedFixes.jl",
authors="Zachary P. Christensen",
)

deploydocs(
repo = "github.com/Tokazama/ChainedFixes.jl.git",
)
6 changes: 6 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ChainedFixes

```@autodocs
Modules = [ChainedFixes]
```

Loading

2 comments on commit d0b68ab

@Tokazama
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/15965

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" d0b68ab9ccf342d74b5f7d3cd23dcce83b9becc2
git push origin v0.2.0

Please sign in to comment.