This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Partially apply maybes to a function, useful for creating records.
version 1.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.0.0
Committed At 2018-07-18 06:51:52 UTC
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

README

Maybe.Applicator

A helper function for partially applying "Maybe" values to a function.

I made this because I found myself using a pattern where I was creating temporary potential records (for forms, usually) like this:

```elm
  type alias Record =
    { x : String
    , y : String
    , z : String
    }
  
  type alias NewRecord =
    { x : Maybe String
    , y : Maybe String
    , z : Maybe String
    }
```

And then when it came time to submit I'd have a helper function like this: elm createRecordOrNothing : NewRecord -> Maybe Record createRecordOrNothing newRecord = case ( x = newRecord.x , y = newRecord.y , z = newRecord.z ) of ( Just x , Just y , Just z ) -> Just Record x y z _ -> Nothing

Which needless to say is ugly. And fails with records larger than 10 fields. (_tuple10 is not defined)

I figured there had to be a way to do this neatly partially applying arguments to the record constructors and returning Nothing if an invalid parameter popped up. This is what I came up with, there may be a better solution out there, I'm new to both Functional Programming and Elm, but I couldn't find a package or pattern out there like this one so I'm publishing my first ever pacakge for anything. I'd love some feedback if you stumble across it. Anyway, here's how I use it, I'm hoping that it comes in handy in this or other circumstances:

```elm
  createRecordOrNothing : NewRecord -> Maybe Record
  createRecordOrNothing newRecord =
    ( Just Record )
      |> Maybe.Applicator.apply newRecord.x
      |> Maybe.Applicator.apply newRecord.y
      |> Maybe.Applicator.apply newRecord.z
```

I know this could have better tests. If anyone is willing to guide me on that front I'd be incredibly grateful!