https://github.com/bburdette/toop
tuple-like datastructure allowing more than 3 elements
https://github.com/bburdette/toop
Last synced: 2 months ago
JSON representation
tuple-like datastructure allowing more than 3 elements
- Host: GitHub
- URL: https://github.com/bburdette/toop
- Owner: bburdette
- License: bsd-3-clause
- Created: 2019-04-23T00:30:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-24T21:42:31.000Z (over 3 years ago)
- Last Synced: 2025-01-21T19:51:15.604Z (4 months ago)
- Language: Elm
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Toop
A set of tuple-like data structures that allow more than 3 elements.
The main thing I use Toop for is in case statements, to pattern match
multiple things at once:```elm
import Toop
case Toop.T4 mba mbb mbc mbd of
Toop.T4 (Just a) (Just b) (Just c) (Just d) ->
-- we've got all the things!
_ ->
-- failure to get all the things.```
## applyT functions.
apply calls a function using the Toop elements as the arguments.
```elm
args = Toop.T6 "this" 5 "that" 6 (<) "less than"
comp name1 val1 name2 val2 op opname =
if op val1 val2 then
name1 ++ " is " ++ opname ++ name2
else
name2 ++ " is " ++ opname ++ name1resultString = Toop.Apply.applyT6 comp args
```
## takeT functions:
```elm
nums = [1 3 5 2 4 6 8 9]
fiveDmath : Toop.T5 Float Float Float Float Float
fiveDmath args =
-- some kind of calculation involving exactly 5 numbersmbresult = (Toop.Take.takeT5 nums) |> Maybe.map fiveDmath
```
## resT functions:
```elm
type EditState
= MyEdit { uid: Uuid, group: UUID, doc: UUID }
| Failed StringToEdit : String -> String -> String -> EditState
ToEdit uid group doc =
Toop.T3 (UUID.fromString uid) (UUID.fromString group) (UUID.fromString doc)
|> resT3
|> Result.map
(\(Toop.T3 uidid groupid docid) ->
MyEdit { uid = uidid, group = groupid, doc = docid }
)
|> Result.withDefault Failed "invalid uuid"
)
```