Git Product home page Git Product logo

php-fp-maybe's People

Contributors

i-am-tom avatar shadowhand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

roundingwellos

php-fp-maybe's Issues

Release 1.0 and 2.0

Right now there are no tags. The recent work in #6 should only be in 2.0.0.

The following tags should be created:

  • 1.0.0 from 9d57a59
  • 2.0.0 from current master

If you give me write access, I can create these tags. ๐Ÿค“

Have you considered creating interfaces for Algebraic Structures?

This is broader than just Maybe, but I'm not sure if you can create issues for a whole group. Anyhow, I've been working on an implementation of Task, and found myself wanting a liftA2() function. It struck me that there's at least three ways to approach how I declare the function signature:

Option 1: Nailed-down types

function liftA2(callable $f, Task $a1, Task $a2) {
    return $a1->map(function ($a1Val) use ($f) {
        return function($x) use ($a1Val) {
            return $f($a1Val, $x);
        }
    })->ap($a2);
}

Option 2: No type checking

function liftA2(callable $f, $a1, $a2) {
    return $a1->map(function ($a1Val) use ($f) {
        return function($x) use ($a1Val) {
            return $f($a1Val, $x);
        }
    })->ap($a2);
}

Option 3: Interface type checking

function liftA2(callable $f, Functor $a1, Applicative $a2) {
    return $a1->map(function ($a1Val) use ($f) {
        return function($x) use ($a1Val) {
            return $f($a1Val, $x);
        }
    })->ap($a2);
}

Option 1 works, but isn't terribly flexible. Option 2 also works, until someone tries to pass in something without a ->ap() or ->map() method. I could manually check for the given method with reflection, but it seems a pain. Option 3 would mean that PHP did the checking for me, and would allow me to re-use liftA2() across different types. But it would also mean that I have to make sure that all the types I want to use it with implement that interface.

I haven't actually tried it, so I don't know if there's good reasons not to. Is this something you've thought about?

Maybe without value check?

Is Maybe missing a constructor that returns Just for a value, or Nothing for a null? From what I can tell, Haskell's Maybe constructor does a type check and returns a Just when given a value and Nothing otherwise. Would it make sense to have the following?

$maybe = Maybe::of(null);
assert($maybe instanceof Nothing);

$maybe = Maybe::of(1);
assert($maybe instanceof Just);

Or, if the violates the Applicative constructor, perhaps the following?

$maybe = Maybe::maybe(null); // Nothing
$maybe = Maybe::maybe(1); // Just
$maybe = Maybe::maybe(false); // Just

Update `autoload-dev` within Composer

Currently, the tests are only running because no tests have any dependencies under PhpFp\Maybe\Test, and PHPUnit doesn't let poor autoloading get in its way. There needs to be a separate Composer entry, for autoload-dev, to load the tests namespace.

PSR the README Examples

I forgot to do this in my sweep! The examples should be in line with the coding standard.

Support conversion to Either

Would it make sense to have a Maybe::toEither(): Either method?

abstract class Maybe
{
    // ...
    public function toEither(): Either
    {
        return $this->map('\PhpFp\Either\Either::of')->fork(Either::left(null));
    }
}

Or perhaps it would be better to have abstract public function toEither(): Either implemented as:

// Just
public function toEither(): Either
{
    return Either::of($this->value);
}

// Nothing
public function toEither(): Either
{
    return Either::left(null);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.