Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Curried/partially applied form? #10

Open
oxinabox opened this issue Apr 14, 2019 · 4 comments
Open

Add Curried/partially applied form? #10

oxinabox opened this issue Apr 14, 2019 · 4 comments
Milestone

Comments

@oxinabox
Copy link
Member

oxinabox commented Apr 14, 2019

If everything that takes 2 arguments:
i.e. the Filters and the Transform
had an overload to just take the nonlogger argument,
then it might be prettier

Rather than writing:

const ConsoleLogger(stream, min_level) = 
	MinLevelLogger(
		ActiveFilteredLogger(max_log_filter,
			PureConsoleLogger(stream)
		),
		min_level
	)

we could write ∘

const ConsoleLogger(stream, min_level) = 
	MinLevelLogger(min_level) ∘ ActiveFilteredLogger(max_log_filter) ∘ PureConsoleLogger(stream)

Which would pleasently drive home the compositional nature of the system.

@oxinabox
Copy link
Member Author

cf this thread
#9 (comment)

@oxinabox oxinabox added this to the 1.0 milestone Apr 23, 2019
@oxinabox
Copy link
Member Author

oxinabox commented Sep 23, 2019

I am now thinking overloading constructors so they don't construct is too evil.

Maybe they should all have lowercase varients for that.

@oxinabox
Copy link
Member Author

oxinabox commented Oct 23, 2019

Playing with some things

using Logging: Warn, Info

@testset "1 composition Example" begin
    constructor_form = MinLevelLogger(FileLogger("warn.log"), Warn))
    curried_form = min_level_logger(Warn)(FileLogger("warn.log"))
    piped_form = FileLogger("warn.log") |> min_level_logger(Warn)
    @test constructor_form == curried_form ==  piped_form
end

@testset "2 compositions Example" begin
    constructor_form = MinLevelLogger(
        EarlyFilteredLogger(
            log->log._module==Main,
            FileLogger("warn.log"),
        ),
        Warn
    )

    comp_logger1 = min_level_logger(Warn)  EarlyFilteredLogger(log->log._module==Main)
    comp_form = comp_logger1(FileLogger("warn.log"))

    level_filter = min_level_logger(Warn)
    module_filter = EarlyFilteredLogger(log->log._module==Main)
    curried_form = level_filter(module_filter(FileLogger("warn.log")))

    @test comp_form == constructor_form == curried_form
end

@oxinabox
Copy link
Member Author

oxinabox commented Oct 23, 2019

Tee could be weirder,
idk which if any of these should be allowed

using Logging: Warn, Info
@testset "Tee and merge" begin
    sink = FileLogger("all.log")
    constructed_form = TeeLogger(
        MinLevelLogger(sink, Info),
        MinLevelLogger(sink, Warn),
    );

    curried_form = tee_logger(
        min_level_logger(Warn),
        min_level_logger(Warn)
    )(sink)

    curried_form2 = tee_logger(
        min_level_logger(Warn),
        min_level_logger(Warn)
    )(sink, sink)


    @test constructed_form == curried_form == curried_form2
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant