Dever v0.0.2
This commit is contained in:
commit
e6e175ebcf
816 files changed
+120349
No files matched your search
@@ -0,0 +1,515 @@
|
||||
putCount(value: Int, previous: Map<Int, Int>) (out: Map<Int, Int>) {
|
||||
key = length(previous)
|
||||
out = put(previous, key, value + key)
|
||||
}
|
||||
|
||||
loop growMap(values: List<Int>, seed: Map<Int, Int>) (out: Map<Int, Int>)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, putCount(value, acc)) |
|
||||
|
||||
keepMap(values: List<Int>, seed: Map<Int, Int>) (updated: Map<Int, Int>, original: Map<Int, Int>) {
|
||||
updated = growMap(values, seed)
|
||||
original = seed
|
||||
}
|
||||
|
||||
putKey(previous: Map<Int, Int>, value: Int) (out: Map<Int, Int>) {
|
||||
out = put(previous, value % 2, value)
|
||||
}
|
||||
|
||||
loop replaceKeys(start: Int, end: Int) (out: Map<Int, Int>)
|
||||
| each value in range(start, end) | result |
|
||||
| out | fold(acc = {}, putKey(acc, value)) |
|
||||
|
||||
loop growBytes(values: Bytes) (out: List<Int>)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = [], addValue(value, acc)) |
|
||||
|
||||
mapKeyFault(value: Int, previous: Map<Int, Int>) (out: Map<Int, Int>) {
|
||||
key = value + 9_223_372_036_854_775_807
|
||||
out = put(previous, key, value)
|
||||
}
|
||||
|
||||
loop mapFault(values: List<Int>) (out: Map<Int, Int>)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = {}, mapKeyFault(value, acc)) |
|
||||
|
||||
accumulate(value: Int, previous: Int) (out: Int) { out = previous + value }
|
||||
|
||||
type Cursor { position: Int, end: Int }
|
||||
|
||||
rule cursorNext(more: Bool, cursor: Cursor) (out: Walk<Int, Cursor>)
|
||||
| more | cursor | out |
|
||||
| true | - | Next(cursor.position, Cursor { position = cursor.position + 1, end = cursor.end }) |
|
||||
| false | - | Done |
|
||||
|
||||
advance(cursor: Cursor) (out: Walk<Int, Cursor>) {
|
||||
out = cursorNext(cursor.position < cursor.end, cursor)
|
||||
}
|
||||
|
||||
advanceChecked(cursor: Cursor) (out: Walk<Int, Cursor>) {
|
||||
check cursor.position <= 1 else Invalid
|
||||
out = advance(cursor)
|
||||
}
|
||||
|
||||
loop walked(start: Int, end: Int) (items: List<Int>, total: Int)
|
||||
| each value in walk(Cursor { position = start, end = end }, advance) | result |
|
||||
| items | list value |
|
||||
| total | sum value |
|
||||
|
||||
loop walkFirst() (out: Int?)
|
||||
| each value in walk(Cursor { position = 0, end = 5 }, advanceChecked) | result |
|
||||
| out | first value |
|
||||
|
||||
loop walkMixed() (first: Int?, total: Int)
|
||||
| each value in walk(Cursor { position = 0, end = 5 }, advanceChecked) | result |
|
||||
| first | first value |
|
||||
| total | sum value |
|
||||
|
||||
loop walkNone() (out: List<Int>)
|
||||
| each value in walk(Cursor { position = 2, end = 5 }, advanceChecked) | take | result |
|
||||
| out | 0 | list value |
|
||||
|
||||
rule textNext(state: Text) (out: Walk<Text, Text>)
|
||||
| state | out |
|
||||
| "" | Walk.Done |
|
||||
| other | Walk.Next(state, "") |
|
||||
|
||||
loop walkText(seed: Text) (out: List<Text>)
|
||||
| each value in walk(seed, textNext) | result |
|
||||
| out | list value |
|
||||
|
||||
loop walkTextSize(seed: Text) (out: Int)
|
||||
| each value in walk(seed, textNext) | result |
|
||||
| out | sum length(value) |
|
||||
|
||||
decimalAdd(value: Decimal, previous: Decimal) (out: Decimal) { out = previous + value }
|
||||
floatAdd(value: Float, previous: Float) (out: Float) { out = previous + value }
|
||||
|
||||
loop decimalFold(values: List<Decimal>) (out: Decimal)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = 0, decimalAdd(value, acc)) |
|
||||
|
||||
loop floatFold(values: List<Float>) (out: Float)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = 0.0, floatAdd(value, acc)) |
|
||||
|
||||
type FoldState { title: Text, count: Int }
|
||||
|
||||
countNext(value: Int, previous: FoldState) (out: FoldState) {
|
||||
out = FoldState { title = previous.title, count = previous.count + value }
|
||||
}
|
||||
|
||||
loop countState(values: List<Int>, seed: FoldState) (out: FoldState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, countNext(value, acc)) |
|
||||
|
||||
sharedState(values: List<Int>, seed: FoldState) (out: FoldState, original: FoldState) {
|
||||
out = countState(values, seed)
|
||||
original = seed
|
||||
}
|
||||
|
||||
loop folded(values: List<Int>, seed: Int) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, accumulate(value, acc)) |
|
||||
|
||||
accumulateUntil(value: Int, previous: Int, limit: Int) (acc: Int, stop: Bool) {
|
||||
acc = previous + value
|
||||
stop = acc >= limit
|
||||
}
|
||||
|
||||
loop bounded(values: List<Int>, limit: Int) (first: Int, total: Int)
|
||||
| each value in values | result |
|
||||
| first | foldUntil(acc = 0, accumulateUntil(value, acc, limit)) |
|
||||
| total | fold(acc = 0, accumulate(value, acc)) |
|
||||
|
||||
addValue(value: Int, previous: List<Int>) (out: List<Int>) { out = append(previous, value) }
|
||||
|
||||
loop foldList(values: List<Int>) (out: List<Int>)
|
||||
| each value in values | value | result |
|
||||
| out | > 0 | fold(acc = [], addValue(value, acc)) |
|
||||
|
||||
keepText(previous: Text) (out: Text) { out = previous }
|
||||
|
||||
loop keepSeed(values: List<Int>, seed: Text) (out: Text)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, keepText(acc)) |
|
||||
|
||||
findValue(value: Int) (acc: Int?, stop: Bool) {
|
||||
acc = value
|
||||
stop = value > 0
|
||||
}
|
||||
|
||||
loop findFold(values: List<Int>) (out: Int?)
|
||||
| each value in values | result |
|
||||
| out | foldUntil(previous = null, findValue(value)) |
|
||||
|
||||
checkedAdd(value: Int, previous: Int) (out: Int) { out = previous + checked(value) }
|
||||
|
||||
loop checkedFold(values: List<Int>) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = 0, checkedAdd(value, acc)) |
|
||||
|
||||
badSource() (out: List<Int>) { fail(Invalid) }
|
||||
badSeed() (out: Int) { fail(Forbidden) }
|
||||
|
||||
badUpdate(previous: Int) (acc: Int, stop: Bool) { fail(Conflict) }
|
||||
|
||||
loop updateFailure(values: List<Int>) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | foldUntil(acc = 7, badUpdate(acc)) |
|
||||
|
||||
loop rangeFailure() (out: Int)
|
||||
| each value in range(badSeed(), 10) | result |
|
||||
| out | fold(acc = 0, accumulate(value, acc)) |
|
||||
|
||||
loop rangeEndFailure() (out: Int)
|
||||
| each value in range(0, badSeed()) | result |
|
||||
| out | fold(acc = 0, accumulate(value, acc)) |
|
||||
|
||||
loop sourceBeforeSeed() (out: Int)
|
||||
| each value in badSource() | result |
|
||||
| out | fold(acc = badSeed(), accumulate(value, acc)) |
|
||||
|
||||
loop seedBeforeConsume(values: List<Int>) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = badSeed(), accumulate(value, acc)) |
|
||||
|
||||
loop indexed(values: List<Int>) (out: Map<Int, Int>)
|
||||
| each value in values | result |
|
||||
| out | index value |
|
||||
|
||||
type IndexResult { Ready(value: Map<Int, Int>), error Duplicate(reason: dever.collection.Error) }
|
||||
|
||||
captureIndex(values: List<Int>) (out: IndexResult) { out = result(indexed(values)) }
|
||||
|
||||
loop indexNames(values: List<Text>) (out: Map<Int, Text>)
|
||||
| each value in values | result |
|
||||
| out | index length(value) |
|
||||
|
||||
loop indexFiltered(values: List<Int>) (out: Map<Int, Int>)
|
||||
| each value in values | value | result |
|
||||
| out | >= 0 | index checked(value) |
|
||||
|
||||
loop indexFailure(values: List<Int>) (out: Map<Int, Int>)
|
||||
| each value in values | result |
|
||||
| out | index checked(value) |
|
||||
|
||||
loop grouped(values: List<Int>) (out: Map<Int, List<Int>>)
|
||||
| each value in values | result |
|
||||
| out | group value % 2 |
|
||||
|
||||
loop groupNames(values: List<Text>) (out: Map<Int, List<Text>>)
|
||||
| each value in values | result |
|
||||
| out | group length(value) |
|
||||
|
||||
loop groupCopies(values: List<Text>) (copy: List<Text>, out: Map<Text, List<Text>>)
|
||||
| each value in values | result |
|
||||
| copy | list value |
|
||||
| out | group value |
|
||||
|
||||
loop groupFiltered(values: List<Int>) (out: Map<Int, List<Int>>)
|
||||
| each value in values | value | result |
|
||||
| out | >= 0 | group checked(value) |
|
||||
|
||||
loop groupFailure(values: List<Int>) (out: Map<Int, List<Int>>)
|
||||
| each value in values | result |
|
||||
| out | group checked(value) |
|
||||
|
||||
loop totals(values: List<Int>) (total: Int, items: List<Int>, count: Int >= 0, first: Int?, smallest: Int?, largest: Int?)
|
||||
| each value in values | result |
|
||||
| largest | max value |
|
||||
| count | count |
|
||||
| total | sum value |
|
||||
| items | list value |
|
||||
| first | first value |
|
||||
| smallest | min value |
|
||||
|
||||
loop ranged(start: Int, end: Int) (total: Int, count: Int)
|
||||
| each value in range(start, end) | result |
|
||||
| total | sum value |
|
||||
| count | count |
|
||||
|
||||
positive(value: Int) (out: Bool) {
|
||||
check value >= 0 else Invalid
|
||||
out = value > 0
|
||||
}
|
||||
|
||||
checked(value: Int) (out: Int) {
|
||||
check value >= 0 else Invalid
|
||||
out = value
|
||||
}
|
||||
|
||||
loop anyPositive(values: List<Int>) (out: Bool)
|
||||
| each value in values | result |
|
||||
| out | any positive(value) |
|
||||
|
||||
loop allPositive(values: List<Int>) (out: Bool)
|
||||
| each value in values | result |
|
||||
| out | all positive(value) |
|
||||
|
||||
loop firstPositive(values: List<Int>) (out: Int?)
|
||||
| each value in values | result |
|
||||
| out | first checked(value) |
|
||||
|
||||
loop mixed(values: List<Int>) (first: Int?, total: Int)
|
||||
| each value in values | result |
|
||||
| first | first checked(value) |
|
||||
| total | sum checked(value) |
|
||||
|
||||
loop names(values: List<Text>) (copied: List<Text>, first: Text?, smallest: Text?)
|
||||
| each value in values | result |
|
||||
| copied | list value |
|
||||
| first | first value |
|
||||
| smallest | min value |
|
||||
|
||||
loop repeated(values: List<Int>, label: Text) (out: List<Text>)
|
||||
| each value in values | result |
|
||||
| out | list label |
|
||||
|
||||
loop decimalTotal(values: List<Decimal>) (out: Decimal)
|
||||
| each value in values | result |
|
||||
| out | sum value |
|
||||
|
||||
loop floatTotal(values: List<Float>) (out: Float)
|
||||
| each value in values | result |
|
||||
| out | sum value |
|
||||
|
||||
loop action(values: List<Int>) ()
|
||||
| each value in values | result |
|
||||
| - | do checked(value) |
|
||||
|
||||
loop actionCount(values: List<Int>) (count: Int)
|
||||
| each value in values | result |
|
||||
| count | do checked(value) |
|
||||
|
||||
flow main() (out: Int)
|
||||
| step | kind | do |
|
||||
| result | loop | ranged(0, 5) |
|
||||
| out | calc | result.total |
|
||||
loop filtered(values: List<Int>) (positive: List<Int>, first: Int?, count: Int, total: Int)
|
||||
| each value in values | value | 12 / value | result |
|
||||
| positive | > 0 | - | list value |
|
||||
| first | > 0 | >= 2 | first value |
|
||||
| count | - | - | count |
|
||||
| total | < 0, > 0 | - | sum value |
|
||||
|
||||
loop optionalNames(values: List<Text?>) (missing: Int, selected: List<Text?>)
|
||||
| each value in values | value | result |
|
||||
| missing | null | count |
|
||||
| selected | "甲", "乙" | list value |
|
||||
|
||||
loop filteredFailure(values: List<Int>) (out: Int?)
|
||||
| each value in values | value | result |
|
||||
| out | >= 0 | first checked(value) |
|
||||
|
||||
loop filteredOwned(values: List<Text>) (copied: List<Text>, selected: Int)
|
||||
| each value in values | length(value + "!") | result |
|
||||
| copied | > 1 | list value |
|
||||
| selected | > 1 | count |
|
||||
|
||||
positiveOnly(value: Int >= 1) (out: Int) { out = value }
|
||||
|
||||
loop refined(values: List<Int?>) (out: List<Int>)
|
||||
| each value in values | value | result |
|
||||
| out | >= 1 | list positiveOnly(value) |
|
||||
|
||||
loop refinedNames(values: List<Text?>) (out: List<Text>, count: Int)
|
||||
| each value in values | value | result |
|
||||
| out | "甲", "乙" | list value |
|
||||
| count | - | count |
|
||||
|
||||
type Event { Named(label: Text), Tagged(label: Text), Empty }
|
||||
type Envelope { event: Event }
|
||||
type MaybeEnvelope { event: Event? }
|
||||
|
||||
loop payloads(values: List<Event>) (labels: List<Text>, size: Int)
|
||||
| each value in values | value | result |
|
||||
| labels | Named(label), Tagged(label) | list label |
|
||||
| size | Named(label), Tagged(label) | sum length(label) |
|
||||
|
||||
loop payloadFields(values: List<Envelope>) (labels: List<Text>, size: Int)
|
||||
| each value in values | value.event | result |
|
||||
| labels | Named(label), Tagged(label) | list label |
|
||||
| size | Named(label), Tagged(label) | sum length(label) |
|
||||
|
||||
loop optionalPayloads(values: List<MaybeEnvelope>) (labels: List<Text>)
|
||||
| each value in values | value.event | result |
|
||||
| labels | Named(label), Tagged(label) | list label |
|
||||
|
||||
wrap(value: Int) (out: Event?) { out = Event.Named("名") }
|
||||
|
||||
loop computedPayloads(values: List<Int>) (labels: List<Text>)
|
||||
| each value in values | wrap(value) | result |
|
||||
| labels | Named(label), Tagged(label) | list label |
|
||||
|
||||
loop movingPayloads(values: List<Event>) (labels: List<Text>)
|
||||
| each value in values | value | result |
|
||||
| labels | Named(label), Tagged(label) | list label |
|
||||
|
||||
type InputState { Ready, error Broken }
|
||||
|
||||
loop rejectBroken(values: List<InputState>) ()
|
||||
| each value in values | value | result |
|
||||
| - | Broken | do fail(value) |
|
||||
|
||||
loop limited(values: List<Int>, limit: Int >= 0) (out: List<Int>, count: Int)
|
||||
| each value in values | value | take | result |
|
||||
| out | >= 0 | limit | list checked(value) |
|
||||
| count | - | - | count |
|
||||
|
||||
loop takeOnly(values: List<Int>, limit: Int >= 0) (out: List<Int>)
|
||||
| each value in values | take | result |
|
||||
| out | limit | list checked(value) |
|
||||
|
||||
loop takeZero(values: List<Int>) (out: List<Int>)
|
||||
| each value in values | 1 / value | take | result |
|
||||
| out | > 0 | 0 | list checked(value) |
|
||||
|
||||
loop initializeLimit(values: List<Int>, size: Int >= 0) (out: List<Int>)
|
||||
| each value in values | take | result |
|
||||
| out | size + 1 | list value |
|
||||
|
||||
type Ranked { group: Int, score: Decimal, label: Text }
|
||||
|
||||
loop ranked(values: List<Ranked>, limit: Int >= 0) (out: List<Text>, count: Int)
|
||||
| each value in values | sort | take | result |
|
||||
| out | [value.group.asc, value.score.desc] | limit | list value.label |
|
||||
| count | - | - | count |
|
||||
|
||||
loop sortedTexts(values: List<Text>) (out: List<Text>)
|
||||
| each value in values | sort | result |
|
||||
| out | [length(value).asc] | list value |
|
||||
|
||||
loop sortedChecked(values: List<Int>, limit: Int >= 0) (out: List<Int>)
|
||||
| each value in values | sort | take | result |
|
||||
| out | [value.desc] | limit | list checked(value) |
|
||||
|
||||
loop sortBeforeResult(values: List<Int>, limit: Int >= 0) (out: List<Int>)
|
||||
| each value in values | sort | take | result |
|
||||
| out | [(1 / value).asc] | limit | list checked(-1) |
|
||||
|
||||
type ListState { items: List<Int>, left: Int, right: Int }
|
||||
|
||||
inlineNext(previous: ListState, value: Int) (out: ListState) {
|
||||
out = ListState { items = append(previous.items, value), left = previous.right, right = previous.left }
|
||||
}
|
||||
|
||||
loop inlineState(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, inlineNext(acc, value)) |
|
||||
|
||||
keepListState(values: List<Int>, seed: ListState) (updated: ListState, original: ListState) {
|
||||
updated = inlineState(values, seed)
|
||||
original = seed
|
||||
}
|
||||
|
||||
prefixNext(value: Int, previous: ListState) (out: ListState) {
|
||||
count = length(previous.items)
|
||||
out = ListState { left = previous.right + count, items = append(previous.items, value + count), right = previous.left }
|
||||
}
|
||||
|
||||
loop prefixState(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, prefixNext(value, acc)) |
|
||||
|
||||
aliasNext(value: Int, previous: ListState) (out: ListState) {
|
||||
items = append(previous.items, length(previous.items) + value)
|
||||
count = previous.left + 1
|
||||
out = ListState { right = previous.left, left = count, items = items }
|
||||
}
|
||||
|
||||
loop aliasState(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, aliasNext(value, acc)) |
|
||||
|
||||
oldListNext(value: Int, previous: ListState) (out: ListState) {
|
||||
items = append(previous.items, value)
|
||||
count = length(previous.items)
|
||||
out = ListState { items = items, left = count, right = length(items) }
|
||||
}
|
||||
|
||||
loop oldListState(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, oldListNext(value, acc)) |
|
||||
|
||||
stateCount(previous: ListState) (out: Int) { out = length(previous.items) }
|
||||
|
||||
wholeStateNext(value: Int, previous: ListState) (out: ListState) {
|
||||
out = ListState { items = append(previous.items, stateCount(previous) + value), left = previous.left, right = previous.right }
|
||||
}
|
||||
|
||||
loop wholeState(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, wholeStateNext(value, acc)) |
|
||||
|
||||
recordFaultNext(previous: ListState, value: Int) (out: ListState) {
|
||||
out = ListState { left = previous.left + value, items = append(previous.items, 1 // value), right = previous.right }
|
||||
}
|
||||
|
||||
loop recordFault(values: List<Int>, seed: ListState) (out: ListState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, recordFaultNext(acc, value)) |
|
||||
|
||||
type ReadState { items: List<Int>, first: Int? }
|
||||
|
||||
readStateNext(previous: ReadState, value: Int) (out: ReadState) {
|
||||
first = get(previous.items, 0)
|
||||
out = ReadState { items = append(previous.items, value), first = first }
|
||||
}
|
||||
|
||||
loop readState(values: List<Int>, seed: ReadState) (out: ReadState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, readStateNext(acc, value)) |
|
||||
|
||||
type TextState { items: List<Text>, count: Int }
|
||||
|
||||
textStateNext(previous: TextState, value: Int) (out: TextState) {
|
||||
out = TextState { items = append(previous.items, "next"), count = previous.count + value }
|
||||
}
|
||||
|
||||
loop textState(values: List<Int>, seed: TextState) (out: TextState)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, textStateNext(acc, value)) |
|
||||
|
||||
loop sumChecked(values: List<Int>) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | sum value |
|
||||
|
||||
loop sumBeforeFault(values: List<Int>) (out: Int)
|
||||
| each value in values | result |
|
||||
| out | sum 9_223_372_036_854_775_807 // value |
|
||||
|
||||
appendTextPart(value: Text, previous: Text) (out: Text) { out = previous + value }
|
||||
|
||||
loop joinTextParts(values: List<Text>, seed: Text) (out: Text)
|
||||
| each value in values | result |
|
||||
| out | fold(acc = seed, appendTextPart(value, acc)) |
|
||||
|
||||
keepTextParts(values: List<Text>, seed: Text) (out: Text, original: Text) {
|
||||
out = joinTextParts(values, seed)
|
||||
original = seed
|
||||
}
|
||||
|
||||
|
||||
loop projectedKeys(rows: List<MapEntry<Text, Int>>) (out: List<Text>)
|
||||
| each row in rows | result |
|
||||
| out | list row.key |
|
||||
|
||||
loop projectedValues(rows: List<MapEntry<Text, Int>>) (out: List<Int>)
|
||||
| each row in rows | result |
|
||||
| out | list row.value |
|
||||
|
||||
projectEntries(table: Map<Text, Int>) (keys: List<Text>, values: List<Int>, original: Map<Text, Int>) {
|
||||
keys = projectedKeys(entries(table))
|
||||
values = projectedValues(entries(table))
|
||||
original = table
|
||||
}
|
||||
|
||||
loop projectedLists(rows: List<MapEntry<Int, List<Text>>>) (out: List<List<Text>>)
|
||||
| each row in rows | result |
|
||||
| out | list row.value |
|
||||
|
||||
projectLists(table: Map<Int, List<Text>>) (values: List<List<Text>>, original: Map<Int, List<Text>>) {
|
||||
values = projectedLists(entries(table))
|
||||
original = table
|
||||
}
|
||||
Reference in new issue
Block a user