lue-bird/elm-and-or/1.0.0

AndOr

One, the other or both.

type AndOr first second
= Both (And first second)
| Only (Or first second)

Either both or only the first or second.

When (not) to use this? → readme

change

(And first second -> And first second)
-> AndOr first second
-> AndOr first second

In case we have Both, change them based on their current values

import Or




AndOr.Only (Or.First "hello")
    |> AndOr.onBothAlter (Tuple.mapFirst String.toUpper)
--> AndOr.Only (Or.First "hello")


AndOr.Both ( "hello", "there" )
    |> AndOr.onBothAlter (Tuple.mapFirst String.toUpper)
--> AndOr.Both ( "HELLO", "there" )

Prefer a case..of if you handle both cases

(Or first second -> Or first second)
-> AndOr first second
-> AndOr first second

In case we have Only one of them, change it based on its current value

import Or




AndOr.Only (Or.First "hello")
    |> AndOr.onOnlyAlter (Or.onFirstMap String.toUpper)
--> AndOr.Only (Or.First "HELLO")


AndOr.Both ( "hello", "there" )
    |> AndOr.onOnlyAlter (Or.onFirstMap String.toUpper)
--> AndOr.Both ( "hello", "there" )

Prefer a case..of if you handle both cases

transform

justOnBoth : AndOr first second -> Maybe (And first second)

Just if both values are present, Nothing if only one is present

import Or




AndOr.Both ( 0, 1 ) |> AndOr.justOnBoth --> Just ( 0, 1 )


AndOr.Only (Or.First 0) |> AndOr.justOnBoth --> Nothing


AndOr.Only (Or.Second 1) |> AndOr.justOnBoth --> Nothing

Prefer a case..of if you handle both cases

justOnOnly : AndOr first second -> Maybe (Or first second)

Just if only one value is present, Nothing if both are present

import Or




AndOr.Both ( 0, 1 ) |> AndOr.justOnOnly --> Nothing


AndOr.Only (Or.First 0) |> AndOr.justOnOnly --> Just (Or.First 0)


AndOr.Only (Or.Second 1) |> AndOr.justOnOnly --> Just (Or.Second 1)


AndOr.Only (Or.Second 1)
    |> AndOr.justOnOnly
    |> Maybe.andThen Or.justOnSecond
--> Just 1

Prefer a case..of if you handle both cases