├── .changeset ├── README.md └── config.json ├── .eslintrc.cjs ├── .github ├── changeset-version.cjs └── workflows │ ├── publish.yaml │ └── test.yaml ├── .gitignore ├── .gitpod.yml ├── .vscode ├── settings.json └── tasks.json ├── .yarn ├── patches │ └── eslint-plugin-codegen-npm-0.16.1-87770191cd ├── plugins │ └── @yarnpkg │ │ └── plugin-interactive-tools.cjs └── releases │ └── yarn-3.2.2.cjs ├── .yarnrc.yml ├── README.md ├── gitpod.yml ├── package.json ├── packages ├── .placeholder ├── runtime │ ├── .babel.cjs.json │ ├── .babel.mjs.json │ ├── CHANGELOG.md │ ├── _examples │ │ ├── global.ts │ │ └── main.ts │ ├── _src │ │ ├── Brand.ts │ │ ├── Codec.ts │ │ ├── Decoder.ts │ │ ├── Encoder.ts │ │ ├── Guard.ts │ │ ├── Make.ts │ │ ├── Result.ts │ │ ├── global.ts │ │ └── index.ts │ ├── _test │ │ ├── Decoder.test.ts │ │ ├── Encoder.test.ts │ │ ├── Guard.test.ts │ │ ├── Result.test.ts │ │ └── global.ts │ ├── package.json │ ├── tsconfig.build-examples.json │ ├── tsconfig.build-test.json │ ├── tsconfig.build.json │ └── tsconfig.json └── stdlib │ ├── .babel.cjs.json │ ├── .babel.mjs.json │ ├── CHANGELOG.md │ ├── _examples │ ├── associative.ts │ ├── global.ts │ ├── main.ts │ └── recursive.ts │ ├── _src │ ├── collections.ts │ ├── collections │ │ ├── Chunk.ts │ │ ├── Chunk │ │ │ ├── definition.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── Apply.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── ChainRec.ts │ │ │ │ ├── Compact.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Extend.ts │ │ │ │ ├── Filter.ts │ │ │ │ ├── FilterMap.ts │ │ │ │ ├── FilterMapWithIndex.ts │ │ │ │ ├── FilterWithIndex.ts │ │ │ │ ├── Filterable.ts │ │ │ │ ├── FilterableWithIndex.ts │ │ │ │ ├── FoldMap.ts │ │ │ │ ├── FoldMapWithIndex.ts │ │ │ │ ├── Foldable.ts │ │ │ │ ├── FoldableWithIndex.ts │ │ │ │ ├── ForEach.ts │ │ │ │ ├── ForEachWithIndex.ts │ │ │ │ ├── Monad.ts │ │ │ │ ├── Partition.ts │ │ │ │ ├── PartitionMap.ts │ │ │ │ ├── PartitionMapWithIndex.ts │ │ │ │ ├── PartitionWithIndex.ts │ │ │ │ ├── Reduce.ts │ │ │ │ ├── ReduceRight.ts │ │ │ │ ├── ReduceRightWithIndex.ts │ │ │ │ ├── ReduceWithIndex.ts │ │ │ │ ├── Separate.ts │ │ │ │ ├── Wiltable.ts │ │ │ │ ├── WiltableWithIndex.ts │ │ │ │ ├── Witherable.ts │ │ │ │ └── WitherableWithIndex.ts │ │ │ ├── operations.ts │ │ │ ├── operations │ │ │ │ ├── append.ts │ │ │ │ ├── buckets.ts │ │ │ │ ├── builder.ts │ │ │ │ ├── collect.ts │ │ │ │ ├── collectWhile.ts │ │ │ │ ├── collectWithIndex.ts │ │ │ │ ├── compact.ts │ │ │ │ ├── compactF.ts │ │ │ │ ├── compactWithIndexF.ts │ │ │ │ ├── concat.ts │ │ │ │ ├── dedupe.ts │ │ │ │ ├── difference.ts │ │ │ │ ├── drop.ts │ │ │ │ ├── dropRight.ts │ │ │ │ ├── dropWhile.ts │ │ │ │ ├── elem.ts │ │ │ │ ├── empty.ts │ │ │ │ ├── equals.ts │ │ │ │ ├── exists.ts │ │ │ │ ├── extend.ts │ │ │ │ ├── fill.ts │ │ │ │ ├── filter.ts │ │ │ │ ├── filterWithIndex.ts │ │ │ │ ├── find.ts │ │ │ │ ├── findIndex.ts │ │ │ │ ├── findLast.ts │ │ │ │ ├── findLastIndex.ts │ │ │ │ ├── flatMap.ts │ │ │ │ ├── flatten.ts │ │ │ │ ├── forAll.ts │ │ │ │ ├── forAny.ts │ │ │ │ ├── forEach.ts │ │ │ │ ├── forEachF.ts │ │ │ │ ├── forEachWithIndexF.ts │ │ │ │ ├── get.ts │ │ │ │ ├── getAssociative.ts │ │ │ │ ├── getAssociativeIdentity.ts │ │ │ │ ├── getEquivalence.ts │ │ │ │ ├── getOrd.ts │ │ │ │ ├── getShow.ts │ │ │ │ ├── grouped.ts │ │ │ │ ├── head.ts │ │ │ │ ├── indexWhere.ts │ │ │ │ ├── indexWhereFrom.ts │ │ │ │ ├── intersection.ts │ │ │ │ ├── isEmpty.ts │ │ │ │ ├── isNonEmpty.ts │ │ │ │ ├── join.ts │ │ │ │ ├── last.ts │ │ │ │ ├── make.ts │ │ │ │ ├── makeBy.ts │ │ │ │ ├── map.ts │ │ │ │ ├── mapAccum.ts │ │ │ │ ├── mapWithIndex.ts │ │ │ │ ├── materialize.ts │ │ │ │ ├── partition.ts │ │ │ │ ├── partitionMap.ts │ │ │ │ ├── partitionMapWithIndex.ts │ │ │ │ ├── partitionWithIndex.ts │ │ │ │ ├── prepend.ts │ │ │ │ ├── range.ts │ │ │ │ ├── reduce.ts │ │ │ │ ├── reduceRight.ts │ │ │ │ ├── reduceRightWithIndex.ts │ │ │ │ ├── reduceWhile.ts │ │ │ │ ├── reduceWithIndex.ts │ │ │ │ ├── reverse.ts │ │ │ │ ├── reverseBuckets.ts │ │ │ │ ├── separate.ts │ │ │ │ ├── separateF.ts │ │ │ │ ├── separateWithIndexF.ts │ │ │ │ ├── single.ts │ │ │ │ ├── size.ts │ │ │ │ ├── sort.ts │ │ │ │ ├── sortBy.ts │ │ │ │ ├── split.ts │ │ │ │ ├── splitAt.ts │ │ │ │ ├── splitWhere.ts │ │ │ │ ├── tail.ts │ │ │ │ ├── take.ts │ │ │ │ ├── takeRight.ts │ │ │ │ ├── takeWhile.ts │ │ │ │ ├── toArrayLike.ts │ │ │ │ ├── toCollection.ts │ │ │ │ ├── unfold.ts │ │ │ │ ├── union.ts │ │ │ │ ├── uniq.ts │ │ │ │ ├── unit.ts │ │ │ │ ├── unsafeGet.ts │ │ │ │ ├── unsafeHead.ts │ │ │ │ ├── unsafeLast.ts │ │ │ │ ├── unsafeTail.ts │ │ │ │ ├── unzip.ts │ │ │ │ ├── zip.ts │ │ │ │ ├── zipAll.ts │ │ │ │ ├── zipAllWith.ts │ │ │ │ ├── zipWith.ts │ │ │ │ ├── zipWithIndex.ts │ │ │ │ └── zipWithIndexOffset.ts │ │ │ ├── patch.ts │ │ │ └── patch │ │ │ │ ├── definition.ts │ │ │ │ ├── operations.ts │ │ │ │ └── operations │ │ │ │ ├── apply.ts │ │ │ │ ├── combine.ts │ │ │ │ ├── diff.ts │ │ │ │ └── emptyPatch.ts │ │ ├── Collection.ts │ │ ├── Collection │ │ │ ├── definition.ts │ │ │ └── functions.ts │ │ ├── HashMap.ts │ │ ├── HashMap │ │ │ ├── _internal │ │ │ │ ├── array.ts │ │ │ │ ├── bitwise.ts │ │ │ │ ├── config.ts │ │ │ │ ├── hashMap.ts │ │ │ │ └── node.ts │ │ │ ├── definition.ts │ │ │ ├── operations.ts │ │ │ ├── operations │ │ │ │ ├── beginMutation.ts │ │ │ │ ├── collect.ts │ │ │ │ ├── collectWithIndex.ts │ │ │ │ ├── compact.ts │ │ │ │ ├── empty.ts │ │ │ │ ├── endMutation.ts │ │ │ │ ├── filter.ts │ │ │ │ ├── filterWithIndex.ts │ │ │ │ ├── flatMap.ts │ │ │ │ ├── flatMapWithIndex.ts │ │ │ │ ├── forEach.ts │ │ │ │ ├── forEachWithIndex.ts │ │ │ │ ├── from.ts │ │ │ │ ├── get.ts │ │ │ │ ├── getAssociative.ts │ │ │ │ ├── hasHash.ts │ │ │ │ ├── isEmpty.ts │ │ │ │ ├── keySet.ts │ │ │ │ ├── keys.ts │ │ │ │ ├── make.ts │ │ │ │ ├── map.ts │ │ │ │ ├── mapWithIndex.ts │ │ │ │ ├── modify.ts │ │ │ │ ├── modifyHash.ts │ │ │ │ ├── mutate.ts │ │ │ │ ├── node.ts │ │ │ │ ├── reduce.ts │ │ │ │ ├── reduceWithIndex.ts │ │ │ │ ├── remove.ts │ │ │ │ ├── removeMany.ts │ │ │ │ ├── set.ts │ │ │ │ ├── setTree.ts │ │ │ │ ├── size.ts │ │ │ │ ├── toCollection.ts │ │ │ │ ├── union.ts │ │ │ │ ├── unsafeGet.ts │ │ │ │ ├── update.ts │ │ │ │ └── values.ts │ │ │ ├── patch.ts │ │ │ └── patch │ │ │ │ ├── definition.ts │ │ │ │ ├── operations.ts │ │ │ │ └── operations │ │ │ │ ├── apply.ts │ │ │ │ ├── combine.ts │ │ │ │ ├── diff.ts │ │ │ │ └── emptyPatch.ts │ │ ├── HashSet.ts │ │ ├── HashSet │ │ │ ├── _internal │ │ │ │ └── hashSet.ts │ │ │ ├── definition.ts │ │ │ ├── operations.ts │ │ │ ├── operations │ │ │ │ ├── add.ts │ │ │ │ ├── beginMutation.ts │ │ │ │ ├── difference.ts │ │ │ │ ├── empty.ts │ │ │ │ ├── endMutation.ts │ │ │ │ ├── equals.ts │ │ │ │ ├── every.ts │ │ │ │ ├── filter.ts │ │ │ │ ├── flatMap.ts │ │ │ │ ├── forEach.ts │ │ │ │ ├── from.ts │ │ │ │ ├── has.ts │ │ │ │ ├── intersection.ts │ │ │ │ ├── isSubset.ts │ │ │ │ ├── make.ts │ │ │ │ ├── map.ts │ │ │ │ ├── mutate.ts │ │ │ │ ├── partition.ts │ │ │ │ ├── reduce.ts │ │ │ │ ├── remove.ts │ │ │ │ ├── size.ts │ │ │ │ ├── some.ts │ │ │ │ ├── toCollection.ts │ │ │ │ ├── toggle.ts │ │ │ │ ├── union.ts │ │ │ │ └── values.ts │ │ │ ├── patch.ts │ │ │ └── patch │ │ │ │ ├── definition.ts │ │ │ │ ├── operations.ts │ │ │ │ └── operations │ │ │ │ ├── apply.ts │ │ │ │ ├── combine.ts │ │ │ │ ├── diff.ts │ │ │ │ └── emptyPatch.ts │ │ ├── ImmutableArray.ts │ │ ├── ImmutableArray │ │ │ ├── append.ts │ │ │ ├── collect.ts │ │ │ ├── collectWithIndex.ts │ │ │ ├── compact.ts │ │ │ ├── compactF.ts │ │ │ ├── compactWithIndexF.ts │ │ │ ├── concat.ts │ │ │ ├── definition.ts │ │ │ ├── difference.ts │ │ │ ├── dsl.ts │ │ │ ├── dsl │ │ │ │ ├── conditionals.ts │ │ │ │ ├── do.ts │ │ │ │ ├── gen.ts │ │ │ │ ├── matchers.ts │ │ │ │ ├── sequence.ts │ │ │ │ ├── struct.ts │ │ │ │ └── tuple.ts │ │ │ ├── elem.ts │ │ │ ├── empty.ts │ │ │ ├── equals.ts │ │ │ ├── extend.ts │ │ │ ├── filter.ts │ │ │ ├── filterWithIndex.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── forEachF.ts │ │ │ ├── forEachWithIndexF.ts │ │ │ ├── from.ts │ │ │ ├── get.ts │ │ │ ├── getAssociative.ts │ │ │ ├── getAssociativeIdentity.ts │ │ │ ├── getEquivalence.ts │ │ │ ├── getOrd.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── Apply.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── ChainRec.ts │ │ │ │ ├── Compact.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Extend.ts │ │ │ │ ├── Filter.ts │ │ │ │ ├── FilterMap.ts │ │ │ │ ├── FilterMapWithIndex.ts │ │ │ │ ├── FilterWithIndex.ts │ │ │ │ ├── Filterable.ts │ │ │ │ ├── FilterableWithIndex.ts │ │ │ │ ├── FoldMap.ts │ │ │ │ ├── FoldMapWithIndex.ts │ │ │ │ ├── Foldable.ts │ │ │ │ ├── FoldableWithIndex.ts │ │ │ │ ├── ForEach.ts │ │ │ │ ├── ForEachWithIndex.ts │ │ │ │ ├── Monad.ts │ │ │ │ ├── Partition.ts │ │ │ │ ├── PartitionMap.ts │ │ │ │ ├── PartitionMapWithIndex.ts │ │ │ │ ├── PartitionWithIndex.ts │ │ │ │ ├── Reduce.ts │ │ │ │ ├── ReduceRight.ts │ │ │ │ ├── ReduceRightWithIndex.ts │ │ │ │ ├── ReduceWithIndex.ts │ │ │ │ ├── Separate.ts │ │ │ │ ├── Wiltable.ts │ │ │ │ ├── WiltableWithIndex.ts │ │ │ │ ├── Witherable.ts │ │ │ │ └── WitherableWithIndex.ts │ │ │ ├── intersection.ts │ │ │ ├── isEmpty.ts │ │ │ ├── isNonEmpty.ts │ │ │ ├── make.ts │ │ │ ├── map.ts │ │ │ ├── partition.ts │ │ │ ├── partitionMap.ts │ │ │ ├── partitionMapWithIndex.ts │ │ │ ├── partitionWithIndex.ts │ │ │ ├── prepend.ts │ │ │ ├── separate.ts │ │ │ ├── separateF.ts │ │ │ ├── separateWithIndexF.ts │ │ │ ├── size.ts │ │ │ ├── sort.ts │ │ │ ├── sortBy.ts │ │ │ ├── toCollection.ts │ │ │ ├── union.ts │ │ │ ├── uniq.ts │ │ │ ├── zip.ts │ │ │ └── zipWith.ts │ │ ├── ImmutableMap.ts │ │ ├── ImmutableMap │ │ │ ├── compact.ts │ │ │ ├── copy.ts │ │ │ ├── definition.ts │ │ │ ├── empty.ts │ │ │ ├── filter.ts │ │ │ ├── filterMap.ts │ │ │ ├── filterMapWithIndex.ts │ │ │ ├── filterWithIndex.ts │ │ │ ├── from.ts │ │ │ ├── get.ts │ │ │ ├── has.ts │ │ │ ├── isEmpty.ts │ │ │ ├── make.ts │ │ │ ├── map.ts │ │ │ ├── mapWithIndex.ts │ │ │ ├── reduceWithIndex.ts │ │ │ ├── remove.ts │ │ │ ├── removeMany.ts │ │ │ ├── set.ts │ │ │ ├── size.ts │ │ │ ├── union.ts │ │ │ ├── unsafeGet.ts │ │ │ └── update.ts │ │ ├── ImmutableQueue.ts │ │ ├── ImmutableQueue │ │ │ ├── _internal │ │ │ │ └── ImmutableQueueInternal.ts │ │ │ ├── append.ts │ │ │ ├── appendAll.ts │ │ │ ├── definition.ts │ │ │ ├── dequeue.ts │ │ │ ├── drop.ts │ │ │ ├── empty.ts │ │ │ ├── filter.ts │ │ │ ├── find.ts │ │ │ ├── from.ts │ │ │ ├── head.ts │ │ │ ├── make.ts │ │ │ ├── prepend.ts │ │ │ ├── single.ts │ │ │ ├── size.ts │ │ │ └── splitAt.ts │ │ ├── List.ts │ │ ├── List │ │ │ ├── builder.ts │ │ │ ├── concat.ts │ │ │ ├── definition.ts │ │ │ ├── drop.ts │ │ │ ├── empty.ts │ │ │ ├── exists.ts │ │ │ ├── filter.ts │ │ │ ├── find.ts │ │ │ ├── flatMap.ts │ │ │ ├── forAll.ts │ │ │ ├── forAny.ts │ │ │ ├── forEach.ts │ │ │ ├── from.ts │ │ │ ├── head.ts │ │ │ ├── last.ts │ │ │ ├── map.ts │ │ │ ├── partition.ts │ │ │ ├── partitionMap.ts │ │ │ ├── prepend.ts │ │ │ ├── prependAll.ts │ │ │ ├── reduce.ts │ │ │ ├── reverse.ts │ │ │ ├── sortWith.ts │ │ │ ├── splitAt.ts │ │ │ ├── tail.ts │ │ │ ├── toCollection.ts │ │ │ ├── unsafeHead.ts │ │ │ ├── unsafeLast.ts │ │ │ └── unsafeTail.ts │ │ ├── NonEmptyImmutableArray.ts │ │ ├── NonEmptyImmutableArray │ │ │ ├── concat.ts │ │ │ ├── definition.ts │ │ │ ├── flatMap.ts │ │ │ ├── from.ts │ │ │ ├── getAssociative.ts │ │ │ ├── getEquivalence.ts │ │ │ ├── getOrd.ts │ │ │ ├── getShow.ts │ │ │ ├── head.ts │ │ │ ├── init.ts │ │ │ ├── last.ts │ │ │ ├── make.ts │ │ │ ├── map.ts │ │ │ └── tail.ts │ │ ├── ParSeq.ts │ │ ├── ParSeq │ │ │ ├── definition.ts │ │ │ ├── first.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── fold.ts │ │ │ ├── map.ts │ │ │ ├── zip.ts │ │ │ ├── zipLeft.ts │ │ │ ├── zipRight.ts │ │ │ └── zipWith.ts │ │ ├── RedBlackTree.ts │ │ ├── RedBlackTree │ │ │ ├── _internal │ │ │ │ └── RedBlackTreeInternal.ts │ │ │ ├── at.ts │ │ │ ├── backwards.ts │ │ │ ├── definition.ts │ │ │ ├── empty.ts │ │ │ ├── find.ts │ │ │ ├── findFirst.ts │ │ │ ├── first.ts │ │ │ ├── forEach.ts │ │ │ ├── forEachBetween.ts │ │ │ ├── forEachGe.ts │ │ │ ├── forEachLt.ts │ │ │ ├── from.ts │ │ │ ├── ge.ts │ │ │ ├── getAt.ts │ │ │ ├── gt.ts │ │ │ ├── has.ts │ │ │ ├── insert.ts │ │ │ ├── keys.ts │ │ │ ├── last.ts │ │ │ ├── le.ts │ │ │ ├── lt.ts │ │ │ ├── make.ts │ │ │ ├── node.ts │ │ │ ├── reduce.ts │ │ │ ├── reduceWithIndex.ts │ │ │ ├── removeFirst.ts │ │ │ ├── size.ts │ │ │ ├── values.ts │ │ │ ├── visitBetween.ts │ │ │ ├── visitFull.ts │ │ │ ├── visitGe.ts │ │ │ └── visitLt.ts │ │ ├── Set.ts │ │ ├── Set │ │ │ ├── definition.ts │ │ │ ├── empty.ts │ │ │ ├── from.ts │ │ │ └── make.ts │ │ ├── SortedMap.ts │ │ ├── SortedMap │ │ │ ├── _internal │ │ │ │ └── SortedMapInternal.ts │ │ │ ├── definition.ts │ │ │ ├── empty.ts │ │ │ ├── entries.ts │ │ │ ├── from.ts │ │ │ ├── get.ts │ │ │ ├── getOrd.ts │ │ │ ├── has.ts │ │ │ ├── headMaybe.ts │ │ │ ├── isEmpty.ts │ │ │ ├── isNonEmpty.ts │ │ │ ├── keys.ts │ │ │ ├── make.ts │ │ │ ├── map.ts │ │ │ ├── mapWithIndex.ts │ │ │ ├── reduce.ts │ │ │ ├── reduceWithIndex.ts │ │ │ ├── remove.ts │ │ │ ├── set.ts │ │ │ ├── size.ts │ │ │ └── values.ts │ │ ├── SortedSet.ts │ │ ├── SortedSet │ │ │ ├── _internal │ │ │ │ └── SortedSetInternal.ts │ │ │ ├── add.ts │ │ │ ├── definition.ts │ │ │ ├── derive.ts │ │ │ ├── difference.ts │ │ │ ├── empty.ts │ │ │ ├── filter.ts │ │ │ ├── flatMap.ts │ │ │ ├── forAll.ts │ │ │ ├── forAny.ts │ │ │ ├── forEach.ts │ │ │ ├── from.ts │ │ │ ├── getOrd.ts │ │ │ ├── has.ts │ │ │ ├── intersection.ts │ │ │ ├── isSubset.ts │ │ │ ├── make.ts │ │ │ ├── map.ts │ │ │ ├── partition.ts │ │ │ ├── remove.ts │ │ │ ├── size.ts │ │ │ ├── toggle.ts │ │ │ ├── union.ts │ │ │ └── values.ts │ │ ├── Tree.ts │ │ ├── Tree │ │ │ ├── corresponds.ts │ │ │ ├── definition.ts │ │ │ ├── drawTree.ts │ │ │ ├── duplicate.ts │ │ │ ├── elem.ts │ │ │ ├── equals.ts │ │ │ ├── extend.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── fold.ts │ │ │ ├── foldMap.ts │ │ │ ├── forEach.ts │ │ │ ├── forEachF.ts │ │ │ ├── getEquivalence.ts │ │ │ ├── getShow.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── Apply.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Extend.ts │ │ │ │ ├── FoldMap.ts │ │ │ │ ├── ForEach.ts │ │ │ │ ├── Monad.ts │ │ │ │ └── Reduce.ts │ │ │ ├── map.ts │ │ │ ├── reduce.ts │ │ │ ├── unfold.ts │ │ │ ├── zip.ts │ │ │ └── zipWith.ts │ │ ├── mutable.ts │ │ ├── mutable │ │ │ ├── DoublyLinkedList.ts │ │ │ ├── ListBuffer.ts │ │ │ ├── MutableHashMap.ts │ │ │ ├── MutableHashMap │ │ │ │ ├── definition.ts │ │ │ │ ├── empty.ts │ │ │ │ ├── from.ts │ │ │ │ ├── has.ts │ │ │ │ ├── make.ts │ │ │ │ └── modify.ts │ │ │ ├── MutableHashSet.ts │ │ │ ├── MutableHashSet │ │ │ │ ├── definition.ts │ │ │ │ ├── empty.ts │ │ │ │ ├── from.ts │ │ │ │ └── make.ts │ │ │ ├── MutableQueue.ts │ │ │ └── MutableQueue │ │ │ │ ├── _internal │ │ │ │ ├── Bounded.ts │ │ │ │ └── Unbounded.ts │ │ │ │ ├── bounded.ts │ │ │ │ ├── definition.ts │ │ │ │ └── unbounded.ts │ │ ├── weak.ts │ │ └── weak │ │ │ └── IterableWeakMap.ts │ ├── data.ts │ ├── data │ │ ├── AtomicBoolean.ts │ │ ├── AtomicNumber.ts │ │ ├── AtomicReference.ts │ │ ├── Case.ts │ │ ├── Differ.ts │ │ ├── Differ │ │ │ ├── OrPatch.ts │ │ │ ├── OrPatch │ │ │ │ ├── definition.ts │ │ │ │ ├── operations.ts │ │ │ │ └── operations │ │ │ │ │ ├── apply.ts │ │ │ │ │ ├── combine.ts │ │ │ │ │ ├── diff.ts │ │ │ │ │ └── emptyPatch.ts │ │ │ ├── definition.ts │ │ │ ├── operations.ts │ │ │ └── operations │ │ │ │ ├── chunk.ts │ │ │ │ ├── environment.ts │ │ │ │ ├── hashMap.ts │ │ │ │ ├── hashSet.ts │ │ │ │ ├── make.ts │ │ │ │ ├── orElseEither.ts │ │ │ │ ├── transform.ts │ │ │ │ ├── update.ts │ │ │ │ ├── updateWith.ts │ │ │ │ └── zip.ts │ │ ├── Duration.ts │ │ ├── Either.ts │ │ ├── Either │ │ │ ├── ap.ts │ │ │ ├── catchAll.ts │ │ │ ├── compact.ts │ │ │ ├── compactMaybe.ts │ │ │ ├── definition.ts │ │ │ ├── dsl.ts │ │ │ ├── dsl │ │ │ │ ├── branch.ts │ │ │ │ ├── do.ts │ │ │ │ ├── gen.ts │ │ │ │ ├── getCompactF.ts │ │ │ │ ├── getSeparateF.ts │ │ │ │ ├── matchers.ts │ │ │ │ ├── sequence.ts │ │ │ │ ├── struct.ts │ │ │ │ └── tuple.ts │ │ │ ├── duplicate.ts │ │ │ ├── exists.ts │ │ │ ├── extend.ts │ │ │ ├── filterOrElse.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── fold.ts │ │ │ ├── foldMap.ts │ │ │ ├── forEachF.ts │ │ │ ├── fromMaybe.ts │ │ │ ├── fromNullable.ts │ │ │ ├── fromPredicate.ts │ │ │ ├── getAssociative.ts │ │ │ ├── getCompact.ts │ │ │ ├── getCompactable.ts │ │ │ ├── getEquivalence.ts │ │ │ ├── getOrElse.ts │ │ │ ├── getSeparate.ts │ │ │ ├── getShow.ts │ │ │ ├── getValidationApplicative.ts │ │ │ ├── getValidationAssociative.ts │ │ │ ├── getWiltable.ts │ │ │ ├── getWitherable.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeEither.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── ChainRec.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Fail.ts │ │ │ │ ├── FoldMap.ts │ │ │ │ ├── Foldable.ts │ │ │ │ ├── ForEach.ts │ │ │ │ ├── Monad.ts │ │ │ │ ├── Reduce.ts │ │ │ │ ├── ReduceRight.ts │ │ │ │ └── Run.ts │ │ │ ├── map.ts │ │ │ ├── mapBoth.ts │ │ │ ├── mapLeft.ts │ │ │ ├── merge.ts │ │ │ ├── orElse.ts │ │ │ ├── parseJSON.ts │ │ │ ├── reduce.ts │ │ │ ├── reduceRight.ts │ │ │ ├── separate.ts │ │ │ ├── stringifyJSON.ts │ │ │ ├── swap.ts │ │ │ ├── tap.ts │ │ │ ├── tryCatch.ts │ │ │ ├── zip.ts │ │ │ ├── zipLeft.ts │ │ │ ├── zipRight.ts │ │ │ └── zipValidation.ts │ │ ├── Function.ts │ │ ├── Function │ │ │ └── pipe.ts │ │ ├── LazyValue.ts │ │ ├── Match.ts │ │ ├── Maybe.ts │ │ ├── Maybe │ │ │ ├── ap.ts │ │ │ ├── apply.ts │ │ │ ├── definition.ts │ │ │ ├── dsl.ts │ │ │ ├── dsl │ │ │ │ ├── compactF.ts │ │ │ │ ├── conditionals.ts │ │ │ │ ├── do.ts │ │ │ │ ├── forEachF.ts │ │ │ │ ├── gen.ts │ │ │ │ ├── matchers.ts │ │ │ │ ├── separateF.ts │ │ │ │ ├── struct.ts │ │ │ │ └── tuple.ts │ │ │ ├── duplicate.ts │ │ │ ├── exists.ts │ │ │ ├── extend.ts │ │ │ ├── filter.ts │ │ │ ├── filterMap.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── fold.ts │ │ │ ├── fromNullable.ts │ │ │ ├── fromPredicate.ts │ │ │ ├── getAssociative.ts │ │ │ ├── getAssociativeIdentity.ts │ │ │ ├── getEquivalence.ts │ │ │ ├── getOrElse.ts │ │ │ ├── getOrd.ts │ │ │ ├── getRefinement.ts │ │ │ ├── getShow.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeEither.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── Compactable.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Extend.ts │ │ │ │ ├── Fail.ts │ │ │ │ ├── Filterable.ts │ │ │ │ ├── Foldable.ts │ │ │ │ ├── ForEach.ts │ │ │ │ ├── IdentityBoth.ts │ │ │ │ ├── IdentityFlatten.ts │ │ │ │ ├── Monad.ts │ │ │ │ ├── Wiltable.ts │ │ │ │ └── Witherable.ts │ │ │ ├── map.ts │ │ │ ├── mapNullable.ts │ │ │ ├── orElse.ts │ │ │ ├── partition.ts │ │ │ ├── partitionMap.ts │ │ │ ├── separate.ts │ │ │ ├── sequence.ts │ │ │ ├── tap.ts │ │ │ ├── toNullable.ts │ │ │ ├── toUndefined.ts │ │ │ ├── tryCatch.ts │ │ │ ├── zip.ts │ │ │ ├── zipLeft.ts │ │ │ ├── zipRight.ts │ │ │ └── zipWith.ts │ │ ├── Predicate.ts │ │ ├── Stack.ts │ │ └── String.ts │ ├── exceptions.ts │ ├── exceptions │ │ ├── Exception.ts │ │ ├── IndexOutOfBounds.ts │ │ ├── NoSuchElement.ts │ │ └── PrematureGeneratorExit.ts │ ├── global.ts │ ├── index.ts │ ├── io.ts │ ├── io │ │ ├── Eval.ts │ │ ├── Eval │ │ │ ├── definition.ts │ │ │ ├── extend.ts │ │ │ ├── flatMap.ts │ │ │ ├── flatten.ts │ │ │ ├── gen.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Any.ts │ │ │ │ ├── Applicative.ts │ │ │ │ ├── Apply.ts │ │ │ │ ├── AssociativeBoth.ts │ │ │ │ ├── AssociativeFlatten.ts │ │ │ │ ├── Covariant.ts │ │ │ │ ├── Extend.ts │ │ │ │ ├── IdentityBoth.ts │ │ │ │ └── Monad.ts │ │ │ ├── map.ts │ │ │ ├── reduce.ts │ │ │ ├── run.ts │ │ │ ├── struct.ts │ │ │ ├── succeed.ts │ │ │ ├── succeedNow.ts │ │ │ ├── suspend.ts │ │ │ ├── tap.ts │ │ │ ├── tuple.ts │ │ │ ├── unit.ts │ │ │ ├── zip.ts │ │ │ ├── zipLeft.ts │ │ │ ├── zipRight.ts │ │ │ └── zipWith.ts │ │ ├── Random.ts │ │ └── Random │ │ │ ├── Distribution.ts │ │ │ ├── Distribution │ │ │ ├── _internal │ │ │ │ ├── ArrayInt.ts │ │ │ │ ├── uniformArrayIntDistributionInternal.ts │ │ │ │ └── uniformIntDistributionInternal.ts │ │ │ ├── definition.ts │ │ │ ├── operations.ts │ │ │ └── operations │ │ │ │ ├── uniformArrayIntDistribution.ts │ │ │ │ ├── uniformBigIntDistribution.ts │ │ │ │ └── uniformIntDistribution.ts │ │ │ ├── Generator.ts │ │ │ ├── Generator │ │ │ ├── MersenneTwister.ts │ │ │ └── RandomGenerator.ts │ │ │ ├── MutableRandom.ts │ │ │ └── PCGRandom.ts │ ├── prelude.ts │ ├── prelude │ │ ├── Any.ts │ │ ├── Applicative.ts │ │ ├── Apply.ts │ │ ├── Associative.ts │ │ ├── Associative │ │ │ ├── all.ts │ │ │ ├── any.ts │ │ │ ├── definition.ts │ │ │ ├── first.ts │ │ │ ├── fold.ts │ │ │ ├── function.ts │ │ │ ├── intercalate.ts │ │ │ ├── inverted.ts │ │ │ ├── last.ts │ │ │ ├── max.ts │ │ │ ├── min.ts │ │ │ ├── object.ts │ │ │ ├── product.ts │ │ │ ├── string.ts │ │ │ ├── struct.ts │ │ │ ├── sum.ts │ │ │ ├── tuple.ts │ │ │ └── void.ts │ │ ├── AssociativeBoth.ts │ │ ├── AssociativeCompose.ts │ │ ├── AssociativeEither.ts │ │ ├── AssociativeFlatten.ts │ │ ├── AssociativeIdentity.ts │ │ ├── AssociativeIdentity │ │ │ ├── all.ts │ │ │ ├── any.ts │ │ │ ├── definition.ts │ │ │ ├── endomorphism.ts │ │ │ ├── fold.ts │ │ │ ├── fromAssociative.ts │ │ │ ├── function.ts │ │ │ ├── inverted.ts │ │ │ ├── max.ts │ │ │ ├── min.ts │ │ │ ├── product.ts │ │ │ ├── string.ts │ │ │ ├── struct.ts │ │ │ ├── sum.ts │ │ │ ├── tuple.ts │ │ │ └── void.ts │ │ ├── Bounded.ts │ │ ├── Category.ts │ │ ├── ChainRec.ts │ │ ├── Closure.ts │ │ ├── Closure │ │ │ └── definition.ts │ │ ├── CommutativeBoth.ts │ │ ├── CommutativeEither.ts │ │ ├── Compact.ts │ │ ├── Compactable.ts │ │ ├── Contravariant.ts │ │ ├── Covariant.ts │ │ ├── CovariantWithIndex.ts │ │ ├── DSL.ts │ │ ├── DSL │ │ │ ├── _internal │ │ │ │ └── curried.ts │ │ │ ├── apF.ts │ │ │ ├── conditionalF.ts │ │ │ ├── definition.ts │ │ │ ├── flatMapF.ts │ │ │ ├── genF.ts │ │ │ ├── getApplicativeF.ts │ │ │ ├── getApplyF.ts │ │ │ ├── getDoF.ts │ │ │ ├── getValidationF.ts │ │ │ ├── matchers.ts │ │ │ ├── orElseF.ts │ │ │ ├── structF.ts │ │ │ ├── succeedF.ts │ │ │ ├── tupleF.ts │ │ │ └── zip.ts │ │ ├── Derive.ts │ │ ├── Equivalence.ts │ │ ├── Equivalence │ │ │ ├── any.ts │ │ │ ├── array.ts │ │ │ ├── boolean.ts │ │ │ ├── contramap.ts │ │ │ ├── date.ts │ │ │ ├── definition.ts │ │ │ ├── never.ts │ │ │ ├── number.ts │ │ │ ├── orElseEither.ts │ │ │ ├── strict.ts │ │ │ ├── string.ts │ │ │ ├── struct.ts │ │ │ ├── symbol.ts │ │ │ ├── tuple.ts │ │ │ └── zip.ts │ │ ├── Extend.ts │ │ ├── FX.ts │ │ ├── FX │ │ │ ├── Access.ts │ │ │ ├── Fail.ts │ │ │ ├── Provide.ts │ │ │ └── Run.ts │ │ ├── Filter.ts │ │ ├── FilterMap.ts │ │ ├── FilterMapWithIndex.ts │ │ ├── FilterWithIndex.ts │ │ ├── Filterable.ts │ │ ├── FilterableWithIndex.ts │ │ ├── FoldMap.ts │ │ ├── FoldMapWithIndex.ts │ │ ├── Foldable.ts │ │ ├── FoldableWithIndex.ts │ │ ├── ForEach.ts │ │ ├── ForEachWithIndex.ts │ │ ├── HKT.ts │ │ ├── Identity.ts │ │ ├── Identity │ │ │ └── definition.ts │ │ ├── IdentityBoth.ts │ │ ├── IdentityEither.ts │ │ ├── IdentityFlatten.ts │ │ ├── Invariant.ts │ │ ├── Monad.ts │ │ ├── None.ts │ │ ├── Ord.ts │ │ ├── Ord │ │ │ ├── common.ts │ │ │ ├── consecutive.ts │ │ │ ├── definition.ts │ │ │ ├── getAssociative.ts │ │ │ ├── getAssociativeIdentity.ts │ │ │ ├── operations.ts │ │ │ └── tuple.ts │ │ ├── Ordering.ts │ │ ├── Ordering │ │ │ ├── definition.ts │ │ │ ├── instances.ts │ │ │ ├── instances │ │ │ │ ├── Associative.ts │ │ │ │ └── AssociativeIdentity.ts │ │ │ └── operations.ts │ │ ├── Partition.ts │ │ ├── PartitionMap.ts │ │ ├── PartitionMapWithIndex.ts │ │ ├── PartitionWithIndex.ts │ │ ├── Recursive.ts │ │ ├── Recursive │ │ │ ├── Annotated.ts │ │ │ ├── Unfolder.ts │ │ │ ├── definition.ts │ │ │ ├── fold.ts │ │ │ ├── foldAnnotated.ts │ │ │ ├── foldDown.ts │ │ │ ├── foldDownSome.ts │ │ │ ├── foldM.ts │ │ │ ├── foldUp.ts │ │ │ └── unfold.ts │ │ ├── Reduce.ts │ │ ├── ReduceRight.ts │ │ ├── ReduceRightWithIndex.ts │ │ ├── ReduceWithIndex.ts │ │ ├── Selective.ts │ │ ├── Separate.ts │ │ ├── Show.ts │ │ ├── Show │ │ │ ├── boolean.ts │ │ │ ├── definition.ts │ │ │ ├── number.ts │ │ │ ├── string.ts │ │ │ ├── struct.ts │ │ │ └── tuple.ts │ │ ├── Wiltable.ts │ │ ├── WiltableWithIndex.ts │ │ ├── Witherable.ts │ │ └── WitherableWithIndex.ts │ ├── service.ts │ ├── service │ │ ├── Env.ts │ │ ├── Patch.ts │ │ ├── Service.ts │ │ └── Tag.ts │ ├── structure.ts │ ├── structure │ │ ├── Copy.ts │ │ ├── Equals.ts │ │ └── Hash.ts │ ├── type-level.ts │ ├── type-level │ │ ├── check.ts │ │ └── common.ts │ ├── utilities.ts │ └── utilities │ │ ├── Guards.ts │ │ ├── Lazy.ts │ │ └── Types.ts │ ├── _test │ ├── Associative.test.ts │ ├── AssociativeIdentity.test.ts │ ├── Case.test.ts │ ├── Chunk.test.ts │ ├── Collection.test.ts │ ├── Covariant.test.ts │ ├── Differ.test.ts │ ├── Duration.test.ts │ ├── Either.test.ts │ ├── Equals.test.ts │ ├── Eval.test.ts │ ├── Hash.test.ts │ ├── HashMap.test.ts │ ├── HashSet.test.ts │ ├── ImmutableArray.test.ts │ ├── ImmutableMap.test.ts │ ├── ImmutableQueue.test.ts │ ├── IterableWeakMap.test.ts │ ├── LazyValue.test.ts │ ├── List.test.ts │ ├── Match.test.ts │ ├── Maybe.test.ts │ ├── MutableHashMap.test.ts │ ├── MutableHashSet.test.ts │ ├── MutableQueue.test.ts │ ├── NonEmptyImmutableArray.test.ts │ ├── ParSeq.test.ts │ ├── Recursive.test.ts │ ├── RedBlackTree.test.ts │ ├── Service.test.ts │ ├── Show.test.ts │ ├── SortedMap.test.ts │ ├── SortedSet.test.ts │ ├── String.test.ts │ ├── Tree.test.ts │ └── global.ts │ ├── package.json │ ├── tsconfig.build-examples.json │ ├── tsconfig.build-test.json │ ├── tsconfig.build.json │ └── tsconfig.json ├── tsconfig.base.json ├── tsconfig.json ├── tsconfig.madge.json ├── tsplus.config.json ├── vitest.config.ts └── yarn.lock /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@1.6.4/schema.json", 3 | "changelog": [ 4 | "@changesets/changelog-github", 5 | { 6 | "repo": "ts-plus/stdlib" 7 | } 8 | ], 9 | "commit": false, 10 | "linked": [], 11 | "access": "restricted", 12 | "baseBranch": "main", 13 | "updateInternalDependencies": "patch", 14 | "ignore": [] 15 | } -------------------------------------------------------------------------------- /.github/changeset-version.cjs: -------------------------------------------------------------------------------- 1 | const { execSync } = require("node:child_process"); 2 | 3 | execSync("npx changeset version"); 4 | execSync("YARN_ENABLE_IMMUTABLE_INSTALLS=false node .yarn/releases/yarn-3.2.2.cjs"); 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.yarn/* 2 | !/.yarn/releases 3 | !/.yarn/plugins 4 | !/.yarn/sdks 5 | !/.yarn/patches 6 | 7 | coverage/ 8 | *.tsbuildinfo 9 | node_modules/ 10 | yarn-error.log 11 | .ultra.cache.json 12 | .DS_Store 13 | tmp/ 14 | build/ 15 | dist/ 16 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - init: yarn && yarn build 3 | github: 4 | prebuilds: 5 | addCheck: true 6 | vscode: 7 | extensions: 8 | - dbaeumer.vscode-eslint 9 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | plugins: 4 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 5 | spec: "@yarnpkg/plugin-interactive-tools" 6 | 7 | yarnPath: .yarn/releases/yarn-3.2.2.cjs 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Work in progress [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-908a85?logo=gitpod)](https://github.com/ts-plus/stdlib) 2 | -------------------------------------------------------------------------------- /gitpod.yml: -------------------------------------------------------------------------------- 1 | tasks: 2 | - init: yarn && yarn build 3 | github: 4 | prebuilds: 5 | addCheck: true 6 | vscode: 7 | extensions: 8 | - dbaeumer.vscode-eslint 9 | -------------------------------------------------------------------------------- /packages/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ts-plus/stdlib/d0a7c775279d647b48fe6edd123860398a296cd2/packages/.placeholder -------------------------------------------------------------------------------- /packages/runtime/.babel.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "@babel/transform-modules-commonjs" 5 | ], 6 | [ 7 | "annotate-pure-calls" 8 | ] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/runtime/.babel.mjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "replace-import-extension", 5 | { 6 | "extMapping": { 7 | ".js": ".mjs" 8 | } 9 | } 10 | ], 11 | [ 12 | "annotate-pure-calls" 13 | ] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/runtime/_examples/global.ts: -------------------------------------------------------------------------------- 1 | import "@tsplus/runtime/global" 2 | import "@tsplus/stdlib/global" 3 | -------------------------------------------------------------------------------- /packages/runtime/_src/Codec.ts: -------------------------------------------------------------------------------- 1 | export type Codec = 2 | & Decoder 3 | & Encoder 4 | & Guard 5 | & Make 6 | -------------------------------------------------------------------------------- /packages/runtime/_src/index.ts: -------------------------------------------------------------------------------- 1 | export * as brand from "@tsplus/runtime/Brand" 2 | export * as codec from "@tsplus/runtime/Codec" 3 | export * as decoder from "@tsplus/runtime/Decoder" 4 | export * as encoder from "@tsplus/runtime/Encoder" 5 | export * as guard from "@tsplus/runtime/Guard" 6 | export * as make from "@tsplus/runtime/Make" 7 | -------------------------------------------------------------------------------- /packages/runtime/_test/global.ts: -------------------------------------------------------------------------------- 1 | import "@tsplus/runtime/global" 2 | import "@tsplus/stdlib/global" 3 | 4 | /** 5 | * @tsplus global 6 | */ 7 | import { assert, describe, it } from "vitest" 8 | -------------------------------------------------------------------------------- /packages/runtime/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "build/esm", 5 | "declarationDir": "build/dts", 6 | "tsBuildInfoFile": "build/tsbuildinfo/esm.tsbuildinfo", 7 | "tsPlusConfig": "../../tsplus.config.json", 8 | "rootDir": "_src" 9 | }, 10 | "include": ["_src/**/*.ts"], 11 | "references": [{ "path": "../stdlib" }] 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/.babel.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "@babel/transform-modules-commonjs" 5 | ], 6 | [ 7 | "annotate-pure-calls" 8 | ] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/.babel.mjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | [ 4 | "replace-import-extension", 5 | { 6 | "extMapping": { 7 | ".js": ".mjs" 8 | } 9 | } 10 | ], 11 | [ 12 | "annotate-pure-calls" 13 | ] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/stdlib/_examples/global.ts: -------------------------------------------------------------------------------- 1 | import "@tsplus/stdlib/global" 2 | -------------------------------------------------------------------------------- /packages/stdlib/_examples/main.ts: -------------------------------------------------------------------------------- 1 | console.log(ImmutableArray.from(List(0, 1, 2)) == ImmutableArray(0, 1, 2)) 2 | console.log(ImmutableArray.from([0, 1, 2]) == ImmutableArray(0, 1, 2)) 3 | console.log( 4 | pipe( 5 | Maybe(0), 6 | Maybe.$.map((n) => n + 1), 7 | Maybe.$.map((n) => `res: ${n}`) 8 | ) == Maybe("res: 1") 9 | ) 10 | console.log(List(0, 1, 2) == 0 + (1 + List(2))) 11 | console.log(List(0, 1, 2) == List(0, 1) + 2) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Chunk/*.ts, prefix: "@tsplus/stdlib/collections"} 2 | export * from "@tsplus/stdlib/collections/Chunk/definition" 3 | export * from "@tsplus/stdlib/collections/Chunk/instances" 4 | export * from "@tsplus/stdlib/collections/Chunk/operations" 5 | export * from "@tsplus/stdlib/collections/Chunk/patch" 6 | // codegen:end 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => Chunk.single({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops Applicative 3 | */ 4 | export const Applicative = DSL.getApplicativeF(Chunk.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Apply.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Apply" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Apply 5 | */ 6 | export const Apply = HKT.instance>({ 7 | ...Chunk.AssociativeBoth, 8 | ...Chunk.Covariant 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: Chunk.$.zip 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (ffa) => ffa.flatten 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Compact.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Compact" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Compact 5 | */ 6 | export const Compact = HKT.instance>({ 7 | compact: (fa) => fa.compact 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: Chunk.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Extend.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Extend" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Extend 5 | */ 6 | export const Extend = HKT.instance>({ 7 | extend: Chunk.$.extend 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Filter.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Filter" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Filter 5 | */ 6 | export const Filter = HKT.instance>({ 7 | filter: Chunk.$.filter 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FilterMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterMap" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FilterMap 5 | */ 6 | export const FilterMap = HKT.instance>({ 7 | filterMap: Chunk.$.collect 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FilterMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterMapWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FilterMapWithIndex 5 | */ 6 | export const FilterMapWithIndex = HKT.instance>({ 7 | filterMapWithIndex: Chunk.$.collectWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FilterWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FilterWithIndex 5 | */ 6 | export const FilterWithIndex = HKT.instance>({ 7 | filterWithIndex: Chunk.$.filterWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Filterable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Filterable" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Filterable 5 | */ 6 | export const Filterable = HKT.instance>({ 7 | ...Chunk.Filter, 8 | ...Chunk.FilterMap, 9 | ...Chunk.Partition, 10 | ...Chunk.PartitionMap 11 | }) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FoldMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMap" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FoldMap 5 | */ 6 | export const FoldMap = HKT.instance>({ 7 | foldMap: (M) => (f) => (fa) => fa.foldMap(M, f) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FoldMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMapWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FoldMapWithIndex 5 | */ 6 | export const FoldMapWithIndex = HKT.instance>({ 7 | foldMapWithIndex: (M) => (f) => (fa) => fa.foldMapWithIndex(M, (a, i) => f(i, a)) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Foldable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Foldable" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Foldable 5 | */ 6 | export const Foldable = HKT.instance>({ 7 | ...Chunk.FoldMap, 8 | ...Chunk.Reduce, 9 | ...Chunk.ReduceRight 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/FoldableWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldableWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops FoldableWithIndex 5 | */ 6 | export const FoldableWithIndex = HKT.instance>({ 7 | ...Chunk.FoldMapWithIndex, 8 | ...Chunk.ReduceWithIndex, 9 | ...Chunk.ReduceRightWithIndex 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/ForEach.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEach" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops ForEach 5 | */ 6 | export const ForEach = HKT.instance>({ 7 | ...Chunk.Covariant, 8 | forEachF: Chunk.forEachF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/ForEachWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEachWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops ForEachWithIndex 5 | */ 6 | export const ForEachWithIndex = HKT.instance>({ 7 | ...Chunk.Covariant, 8 | forEachWithIndexF: Chunk.forEachWithIndexF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...Chunk.Any, 8 | ...Chunk.Covariant, 9 | ...Chunk.AssociativeFlatten 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Partition.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Partition" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Partition 5 | */ 6 | export const Partition = HKT.instance>({ 7 | partition: Chunk.$.partition 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/PartitionMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionMap" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops PartitionMap 5 | */ 6 | export const PartitionMap = HKT.instance>({ 7 | partitionMap: Chunk.$.partitionMap 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/PartitionMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionMapWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops PartitionMapWithIndex 5 | */ 6 | export const PartitionMapWithIndex = HKT.instance>({ 7 | partitionMapWithIndex: Chunk.$.partitionMapWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/PartitionWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops PartitionWithIndex 5 | */ 6 | export const PartitionWithIndex = HKT.instance>({ 7 | partitionWithIndex: Chunk.$.partitionWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Reduce.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Reduce" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Reduce 5 | */ 6 | export const Reduce = HKT.instance>({ 7 | reduce: Chunk.$.reduce 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/ReduceRight.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceRight" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops ReduceRight 5 | */ 6 | export const ReduceRight = HKT.instance>({ 7 | reduceRight: Chunk.$.reduceRight 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/ReduceRightWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceRightWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops ReduceRightWithIndex 5 | */ 6 | export const ReduceRightWithIndex = HKT.instance>({ 7 | reduceRightWithIndex: Chunk.$.reduceRightWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/ReduceWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops ReduceWithIndex 5 | */ 6 | export const ReduceWithIndex = HKT.instance>({ 7 | reduceWithIndex: Chunk.$.reduceWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Separate.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Separate" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Separate 5 | */ 6 | export const Separate = HKT.instance>({ 7 | separate: (fa) => fa.separate 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Wiltable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Wiltable" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Wiltable 5 | */ 6 | export const Wiltable = HKT.instance>({ 7 | separateF: Chunk.separateF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/WiltableWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/WiltableWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops WiltableWithIndex 5 | */ 6 | export const WiltableWithIndex = HKT.instance>({ 7 | separateWithIndexF: Chunk.separateWithIndexF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/Witherable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Witherable" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops Witherable 5 | */ 6 | export const Witherable = HKT.instance>({ 7 | compactF: Chunk.compactF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/instances/WitherableWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/WitherableWithIndex" 2 | 3 | /** 4 | * @tsplus static Chunk.Ops WitherableWithIndex 5 | */ 6 | export const WitherableWithIndex = HKT.instance>({ 7 | compactWithIndexF: Chunk.compactWithIndexF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/append.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Appends a value to a chunk. 5 | * 6 | * @tsplus static Chunk.Aspects append 7 | * @tsplus pipeable Chunk append 8 | */ 9 | export function append(a: A1) { 10 | return (self: Chunk): Chunk => concreteChunkId(self)._append(a) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/buckets.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Buckets iterator. 5 | * 6 | * @tsplus getter Chunk buckets 7 | */ 8 | export function buckets(self: Chunk): Iterable> { 9 | return concreteChunkId(self)._buckets() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/compact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Filter out optional values 3 | * 4 | * @tsplus getter Chunk compact 5 | */ 6 | export function compact(self: Chunk>): Chunk { 7 | return self.collect((x: Maybe) => x) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/dropRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Drops the last `n` elements. 3 | * 4 | * @tsplus static Chunk.Aspects dropRight 5 | * @tsplus pipeable Chunk dropRight 6 | */ 7 | export function dropRight(n: number) { 8 | return (self: Chunk): Chunk => self.take(Math.max(0, self.length - n)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/empty.ts: -------------------------------------------------------------------------------- 1 | import { _Empty } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Builds an empty chunk. 5 | * 6 | * @tsplus static Chunk.Ops empty 7 | */ 8 | export function empty(): Chunk { 9 | return _Empty 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/equals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Referential equality check. 3 | * 4 | * @tsplus pipeable-operator Chunk == 5 | * @tsplus static Chunk.Aspects equals 6 | * @tsplus pipeable Chunk equals 7 | */ 8 | export function equals(that: Chunk) { 9 | return (self: Chunk): boolean => self.corresponds(that, Equals.equals) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Aspects extend 3 | * @tsplus pipeable Chunk extend 4 | */ 5 | export function extend(f: (chunk: Chunk) => B) { 6 | return (self: Chunk): Chunk => 7 | Chunk.from(self.mapWithIndex((i, _) => f(Chunk.from(self.skip(i))))) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flattens a chunk of chunks into a single chunk by concatenating all chunks. 3 | * 4 | * @tsplus getter Chunk flatten 5 | */ 6 | export function flatten(self: Chunk>): Chunk { 7 | return self.flatMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/forEachF.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops forEachF 3 | */ 4 | export const forEachF: ForEach.Fn = (G) => 5 | (f) => Chunk.forEachWithIndexF(G)((_, a) => f(a)) 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/getAssociative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops getAssociative 3 | */ 4 | export function getAssociative(): Associative> { 5 | return Associative((x, y) => x.concat(y)) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/getAssociativeIdentity.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops getAssociativeIdentity 3 | */ 4 | export function getAssociativeIdentity(): AssociativeIdentity> { 5 | return AssociativeIdentity(Chunk.empty(), (x, y) => x.concat(y)) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/getEquivalence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops getEquivalence 3 | */ 4 | export function getEquivalence(E: Equivalence): Equivalence> { 5 | return Equivalence((x, y) => x === y || x.corresponds(y, E.equals)) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/getShow.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Chunk.Ops getShow 3 | */ 4 | export function getShow(S: Show): Show> { 5 | return Show((chunk) => `Chunk(${chunk.map(S.show).join(", ")})`) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/head.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the first element of this chunk if it exists. 3 | * 4 | * @tsplus getter Chunk head 5 | */ 6 | export function head(self: Chunk): Maybe { 7 | return self.get(0) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/indexWhere.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the first index for which the given predicate is satisfied. 3 | * 4 | * @tsplus static Chunk.Aspects indexWhere 5 | * @tsplus pipeable Chunk indexWhere 6 | */ 7 | export function indexWhere(f: Predicate) { 8 | return (self: Chunk): number => self.indexWhereFrom(0, f) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/isEmpty.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Determines if the chunk is empty. 5 | * 6 | * @tsplus getter Chunk isEmpty 7 | */ 8 | export function isEmpty(self: Chunk): boolean { 9 | return concreteChunkId(self).length === 0 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/isNonEmpty.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Determines if the chunk is empty. 5 | * 6 | * @tsplus getter Chunk isNonEmpty 7 | */ 8 | export function isNonEmpty(self: Chunk): boolean { 9 | return concreteChunkId(self).length !== 0 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/join.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * joins the elements together with "sep" in the middle. 3 | * 4 | * @tsplus static Chunk.Aspects join 5 | * @tsplus pipeable Chunk join 6 | */ 7 | export function join(sep: string) { 8 | return (self: Chunk): string => 9 | self.reduce("", (s, a) => (s.length > 0 ? `${s}${sep}${a}` : a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/last.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Returns the last element of this chunk if it exists. 5 | * 6 | * @tsplus getter Chunk last 7 | */ 8 | export function last(self: Chunk): Maybe { 9 | return self.get(concreteChunkId(self).length - 1) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/makeBy.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Return a chunk of length `n` with element `i` initialized with `f(i)`. 3 | * 4 | * @tsplus static Chunk.Ops makeBy 5 | */ 6 | export function makeBy(n: number, f: (i: number) => A): Chunk { 7 | const b = Chunk.builder() 8 | 9 | for (let i = 0; i < n; i++) { 10 | b.append(f(i)) 11 | } 12 | 13 | return b.build() 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/partition.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Separate elements based on a predicate. 3 | * 4 | * @tsplus static Chunk.Aspects partition 5 | * @tsplus pipeable Chunk partition 6 | */ 7 | export function partition(f: Predicate) { 8 | return (self: Chunk): readonly [Chunk, Chunk] => 9 | self.partitionWithIndex((_, a: A) => f(a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/prepend.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Prepends a value to a chunk. 5 | * 6 | * @tsplus static Chunk.Aspects prepend 7 | * @tsplus pipeable Chunk prepend 8 | */ 9 | export function prepend(a: A1) { 10 | return (self: Chunk): Chunk => concreteChunkId(self)._prepend(a) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/range.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Build a chunk with an integer range with both min/max included. 3 | * 4 | * @tsplus static Chunk.Ops range 5 | */ 6 | export function range(min: number, max: number): Chunk { 7 | let builder = Chunk.empty() 8 | for (let i = min; i <= max; i++) { 9 | builder = builder.append(i) 10 | } 11 | return builder 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/reverse.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Reverse buckets iterator. 5 | * 6 | * @tsplus getter Chunk reverse 7 | */ 8 | export function reverse(self: Chunk): Iterable { 9 | return concreteChunkId(self)._reverse() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/reverseBuckets.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Reverse buckets iterator. 5 | * 6 | * @tsplus getter Chunk reverseBuckets 7 | */ 8 | export function reverseBuckets(self: Chunk): Iterable> { 9 | return concreteChunkId(self)._reverseBuckets() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/separate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Partitions the elements of this chunk into two chunks. 3 | * 4 | * @tsplus getter Chunk separate 5 | */ 6 | export function separate(self: Chunk>): readonly [Chunk, Chunk] { 7 | return self.partitionMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/single.ts: -------------------------------------------------------------------------------- 1 | import { Singleton } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Builds a chunk of a single value. 5 | * 6 | * @tsplus static Chunk.Ops single 7 | */ 8 | export function single(a: A): Chunk { 9 | return new Singleton(a) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/size.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Returns the number of elements in the chunk. 5 | * 6 | * @tsplus getter Chunk size 7 | */ 8 | export function size(self: Chunk) { 9 | return concreteChunkId(self).length 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/sort.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sort the elements of an array in increasing order. 3 | * 4 | * @tsplus static Chunk.Aspects sort 5 | * @tsplus pipeable Chunk sort 6 | */ 7 | export function sort(O: Ord) { 8 | return (self: Chunk): Chunk => Chunk.from(Array.from(self).sort((x, y) => O.compare(x, y))) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/splitAt.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns two splits of this chunk at the specified index. 3 | * 4 | * @tsplus static Chunk.Aspects splitAt 5 | * @tsplus pipeable Chunk splitAt 6 | */ 7 | export function splitAt(n: number) { 8 | return (self: Chunk): readonly [Chunk, Chunk] => [self.take(n), self.drop(n)] 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/tail.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Returns every elements after the first. 5 | * 6 | * @tsplus getter Chunk tail 7 | */ 8 | export function tail(self: Chunk): Maybe> { 9 | return concreteChunkId(self).length > 0 ? Maybe.some(self.drop(1)) : Maybe.none 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/take.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Takes the first `n` elements. 5 | * 6 | * @tsplus static Chunk.Aspects take 7 | * @tsplus pipeable Chunk take 8 | */ 9 | export function take(n: number) { 10 | return (self: Chunk): Chunk => concreteChunkId(self)._take(n) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/takeRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Takes the last `n` elements. 3 | * 4 | * @tsplus static Chunk.Aspects takeRight 5 | * @tsplus pipeable Chunk takeRight 6 | */ 7 | export function takeRight(n: number) { 8 | return (self: Chunk): Chunk => self.drop(self.size - n) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/toArrayLike.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Converts a chunk to an `ArrayLike` (either `Array` or `Buffer`). 5 | * 6 | * @tsplus getter Chunk toArrayLike 7 | */ 8 | export function toArrayLike(self: Chunk): ArrayLike { 9 | return concreteChunkId(self)._arrayLike() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/toCollection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter Chunk toCollection 3 | */ 4 | export function toCollection(self: Chunk): Collection { 5 | return self 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/unit.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The unit chunk. 3 | * 4 | * @tsplus static Chunk.Ops unit 5 | */ 6 | export const unit: Chunk = Chunk.single(undefined) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/unsafeGet.ts: -------------------------------------------------------------------------------- 1 | import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition" 2 | 3 | /** 4 | * Unsafely retrieve a value from a `Chunk`. 5 | * 6 | * @tsplus static Chunk.Aspects unsafeGet 7 | * @tsplus pipeable Chunk unsafeGet 8 | */ 9 | export function unsafeGet(n: number) { 10 | return (self: Chunk): A => concreteChunkId(self)._get(n) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/zip.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Zips this chunk with the specified chunk using the specified combiner. 3 | * 4 | * @tsplus static Chunk.Aspects zip 5 | * @tsplus pipeable Chunk zip 6 | */ 7 | export function zip(that: Chunk) { 8 | return (self: Chunk): Chunk<[A, B]> => self.zipWith(that, (a, b) => [a, b]) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/operations/zipWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Zips this chunk with the index of every element, starting from the initial 3 | * index value. 4 | * 5 | * @tsplus getter Chunk zipWithIndex 6 | */ 7 | export function zipWithIndex(self: Chunk): Chunk { 8 | return self.zipWithIndexOffset(0) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/patch.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/Chunk"} 2 | export * from "@tsplus/stdlib/collections/Chunk/patch/definition" 3 | export * from "@tsplus/stdlib/collections/Chunk/patch/operations" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Chunk/patch/operations/emptyPatch.ts: -------------------------------------------------------------------------------- 1 | import { EmptyChunkPatch } from "@tsplus/stdlib/collections/Chunk/patch/definition" 2 | 3 | /** 4 | * Constructs an empty chunk patch. 5 | * 6 | * @tsplus static Differ.Chunk.Patch.Ops empty 7 | */ 8 | export function emptyPatch(): Differ.Chunk.Patch { 9 | return new EmptyChunkPatch() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Collection.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Collection/*.ts, prefix: "@tsplus/stdlib/collections"} 2 | export * from "@tsplus/stdlib/collections/Collection/definition" 3 | export * from "@tsplus/stdlib/collections/Collection/functions" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/_internal/config.ts: -------------------------------------------------------------------------------- 1 | // Configuration 2 | 3 | export const SIZE = 5 4 | 5 | export const BUCKET_SIZE = Math.pow(2, SIZE) 6 | 7 | export const MASK = BUCKET_SIZE - 1 8 | 9 | export const MAX_INDEX_NODE = BUCKET_SIZE / 2 10 | 11 | export const MIN_ARRAY_NODE = BUCKET_SIZE / 4 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/compact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Filters out `None` values from a `HashMap` of `Maybe`s. 3 | * 4 | * @tsplus getter HashMap compact 5 | */ 6 | export function compact(self: HashMap>): HashMap { 7 | return self.collectWithIndex((_, a) => a) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/endMutation.ts: -------------------------------------------------------------------------------- 1 | import { realHashMap } from "@tsplus/stdlib/collections/HashMap/_internal/hashMap" 2 | 3 | /** 4 | * Marks the `HashMap` as immutable. 5 | * 6 | * @tsplus getter HashMap endMutation 7 | */ 8 | export function endMutation(self: HashMap): HashMap { 9 | realHashMap(self) 10 | self._editable = false 11 | return self 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/forEach.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies the specified function to the values of the `HashMap`. 3 | * 4 | * @tsplus static HashMap.Aspects forEach 5 | * @tsplus pipeable HashMap forEach 6 | */ 7 | export function forEach(f: (v: V) => void) { 8 | return (self: HashMap): void => self.forEachWithIndex((_, value) => f(value)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/get.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Safely lookup the value for the specified key in the `HashMap` using the 3 | * internal hashing function. 4 | * 5 | * @tsplus pipeable-index HashMap 6 | * @tsplus static HashMap.Aspects get 7 | * @tsplus pipeable HashMap get 8 | */ 9 | export function get(key: K) { 10 | return (self: HashMap): Maybe => self.getHash(key, Hash.unknown(key)) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/hasHash.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if the specified key has an entry in the `HashMap` using a custom 3 | * hash. 4 | * 5 | * @tsplus static HashMap.Aspects hasHash 6 | * @tsplus pipeable HashMap hasHash 7 | */ 8 | export function hasHash(key: K, hash: number) { 9 | return (self: HashMap): boolean => self.getHash(key, hash).isSome() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/keySet.ts: -------------------------------------------------------------------------------- 1 | import { HashSetInternal } from "@tsplus/stdlib/collections/HashSet/_internal/hashSet" 2 | 3 | /** 4 | * Returns a `HashSet` of keys within the `HashMap`. 5 | * 6 | * @tsplus getter HashMap keySet 7 | */ 8 | export function keySet(self: HashMap): HashSet { 9 | return new HashSetInternal(self) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Maps over the values of the `HashMap` using the specified function. 3 | * 4 | * @tsplus static HashMap.Aspects map 5 | * @tsplus pipeable HashMap map 6 | */ 7 | export function map(f: (v: V) => A) { 8 | return (self: HashMap): HashMap => 9 | self.reduceWithIndex(HashMap.empty(), (z, k, v) => z.set(k, f(v))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reduces the specified state over the values of the `HashMap`. 3 | * 4 | * @tsplus static HashMap.Aspects reduce 5 | * @tsplus pipeable HashMap reduce 6 | */ 7 | export function reduce(z: Z, f: (z: Z, v: V) => Z) { 8 | return (self: HashMap): Z => self.reduceWithIndex(z, (z, _, v) => f(z, v)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/remove.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Remove the entry for the specified key in the `HashMap` using the internal 3 | * hashing function. 4 | * 5 | * @tsplus static HashMap.Aspects remove 6 | * @tsplus pipeable HashMap remove 7 | */ 8 | export function remove(key: K) { 9 | return (self: HashMap): HashMap => self.modify(key, () => Maybe.none) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/set.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sets the specified key to the specified value using the internal hashing 3 | * function. 4 | * 5 | * @tsplus static HashMap.Aspects set 6 | * @tsplus pipeable HashMap set 7 | */ 8 | export function set(key: K, value: V) { 9 | return (self: HashMap): HashMap => self.modify(key, () => Maybe.some(value)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/size.ts: -------------------------------------------------------------------------------- 1 | import { realHashMap } from "@tsplus/stdlib/collections/HashMap/_internal/hashMap" 2 | 3 | /** 4 | * Returns the number of entries within the `HashMap`. 5 | * 6 | * @tsplus getter HashMap size 7 | */ 8 | export function size(self: HashMap): number { 9 | realHashMap(self) 10 | return self._size 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/toCollection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter HashMap toCollection 3 | */ 4 | export function toCollection(self: HashMap): Collection { 5 | return self 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/operations/update.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Updates the value of the specified key within the `HashMap` if it exists. 3 | * 4 | * @tsplus static HashMap.Aspects update 5 | * @tsplus pipeable HashMap update 6 | */ 7 | export function update(key: K, f: (v: V) => V) { 8 | return (self: HashMap): HashMap => self.modify(key, (maybe) => maybe.map(f)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/patch.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/HashMap"} 2 | export * from "@tsplus/stdlib/collections/HashMap/patch/definition" 3 | export * from "@tsplus/stdlib/collections/HashMap/patch/operations" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashMap/patch/operations/emptyPatch.ts: -------------------------------------------------------------------------------- 1 | import { EmptyHashMapPatch } from "@tsplus/stdlib/collections/HashMap/patch/definition" 2 | 3 | /** 4 | * Constructs an empty map patch. 5 | * 6 | * @tsplus static Differ.HashMap.Patch.Ops empty 7 | */ 8 | export function emptyPatch(): Differ.HashMap.Patch { 9 | return new EmptyHashMapPatch() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./HashSet/*.ts, prefix: "@tsplus/stdlib/collections"} 2 | export * from "@tsplus/stdlib/collections/HashSet/definition" 3 | export * from "@tsplus/stdlib/collections/HashSet/operations" 4 | export * from "@tsplus/stdlib/collections/HashSet/patch" 5 | // codegen:end 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/beginMutation.ts: -------------------------------------------------------------------------------- 1 | import { HashSetInternal, realHashSet } from "@tsplus/stdlib/collections/HashSet/_internal/hashSet" 2 | 3 | /** 4 | * Marks the `HashSet` as mutable. 5 | * 6 | * @tsplus getter HashSet beginMutation 7 | */ 8 | export function beginMutation(self: HashSet): HashSet { 9 | realHashSet(self) 10 | return new HashSetInternal(self._keyMap.beginMutation) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/empty.ts: -------------------------------------------------------------------------------- 1 | import { HashSetInternal } from "@tsplus/stdlib/collections/HashSet/_internal/hashSet" 2 | 3 | /** 4 | * @tsplus static HashSet.Ops empty 5 | */ 6 | export function empty(): HashSet { 7 | return new HashSetInternal(HashMap.empty()) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/every.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` only if all values in the `HashSet` match the specified 3 | * predicate. 4 | * 5 | * @tsplus static HashSet.Aspects every 6 | * @tsplus pipeable HashSet every 7 | */ 8 | export function every(f: Predicate) { 9 | return (self: HashSet): boolean => !self.some((a) => !f(a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/size.ts: -------------------------------------------------------------------------------- 1 | import { realHashSet } from "@tsplus/stdlib/collections/HashSet/_internal/hashSet" 2 | 3 | /** 4 | * Calculates the number of values in the `HashSet`. 5 | * 6 | * @tsplus getter HashSet size 7 | */ 8 | export function size(self: HashSet): number { 9 | realHashSet(self) 10 | return self._keyMap.size 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/toCollection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter HashSet toCollection 3 | */ 4 | export function toCollection(self: HashSet): Collection { 5 | return self 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/operations/values.ts: -------------------------------------------------------------------------------- 1 | import { realHashSet } from "@tsplus/stdlib/collections/HashSet/_internal/hashSet" 2 | 3 | /** 4 | * Returns an `IterableIterator` of the values in the `HashSet`. 5 | * 6 | * @tsplus getter HashSet values 7 | */ 8 | export function values(self: HashSet): IterableIterator { 9 | realHashSet(self) 10 | return self._keyMap.keys 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/patch.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./patch/*.ts, prefix: "@tsplus/stdlib/collections/HashSet"} 2 | export * from "@tsplus/stdlib/collections/HashSet/patch/definition" 3 | export * from "@tsplus/stdlib/collections/HashSet/patch/operations" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/HashSet/patch/operations/emptyPatch.ts: -------------------------------------------------------------------------------- 1 | import { EmptyHashSetPatch } from "@tsplus/stdlib/collections/HashSet/patch/definition" 2 | 3 | /** 4 | * Constructs an empty set patch. 5 | * 6 | * @tsplus static Differ.HashSet.Patch.Ops empty 7 | */ 8 | export function emptyPatch(): Differ.HashSet.Patch { 9 | return new EmptyHashSetPatch() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/collect.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Filters the `ImmutableArray` and maps the output using the specified 3 | * function. 4 | * 5 | * @tsplus static ImmutableArray.Aspects collect 6 | * @tsplus pipeable ImmutableArray collect 7 | */ 8 | export function collect(f: (a: A) => Maybe) { 9 | return (self: ImmutableArray): ImmutableArray => self.collectWithIndex((_, a) => f(a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/compact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Filters out `None` values from the `ImmutableArray`. 3 | * 4 | * @tsplus getter ImmutableArray compact 5 | */ 6 | export function compact(self: ImmutableArray>): ImmutableArray { 7 | return self.collect(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/dsl/conditionals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus fluent ImmutableArray if 3 | */ 4 | export const branch_ = DSL.conditionalF_() 5 | 6 | /** 7 | * @tsplus static ImmutableArray.Ops if 8 | */ 9 | export const branch = DSL.conditionalF() 10 | 11 | export { branch as if, branch_ as if_ } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/dsl/sequence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops sequence 3 | */ 4 | export const sequence = ForEach.sequenceF(ImmutableArray.ForEach) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/dsl/struct.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops structZip 3 | */ 4 | export const structZip = DSL.structF(ImmutableArray.Apply) 5 | 6 | /** 7 | * @tsplus static ImmutableArray.Ops struct 8 | */ 9 | export const struct = DSL.structF(ImmutableArray.Applicative) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/dsl/tuple.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops tupleZip 3 | */ 4 | export const tupleZip = DSL.tupleF(ImmutableArray.Apply) 5 | 6 | /** 7 | * @tsplus static ImmutableArray.Ops tuple 8 | */ 9 | export const tuple = DSL.tupleF(ImmutableArray.Applicative) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops empty 3 | */ 4 | export function empty(): ImmutableArray { 5 | return new ImmutableArray([]) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/flatMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Aspects flatMap 3 | * @tsplus pipeable ImmutableArray flatMap 4 | */ 5 | export function flatMap(f: (a: A) => ImmutableArray) { 6 | return (self: ImmutableArray): ImmutableArray => 7 | new ImmutableArray(self.array.flatMap(x => f(x).array)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flattens nested `ImmutableArray`s. 3 | * 4 | * @tsplus getter ImmutableArray flatten 5 | */ 6 | export function flatten(self: ImmutableArray>): ImmutableArray { 7 | return self.flatMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/forEachF.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops forEachF 3 | */ 4 | export const forEachF: ForEach.Fn = (G) => 5 | (f) => ImmutableArray.forEachWithIndexF(G)((_, a) => f(a)) 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/from.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops from 3 | * @tsplus getter Collection toImmutableArray 4 | */ 5 | export function from(iterable: Collection): ImmutableArray { 6 | return new ImmutableArray(Array.from(iterable)) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/get.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus pipeable-index ImmutableArray 3 | * @tsplus static ImmutableArray.Aspects get 4 | * @tsplus pipeable ImmutableArray get 5 | */ 6 | export function get(index: number) { 7 | return (self: ImmutableArray): Maybe> => 8 | Maybe.fromNullable(self.array[index]) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/getAssociative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops getAssociative 3 | */ 4 | export function getAssociative(): Associative> { 5 | return Associative((x, y) => x.concat(y)) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/getAssociativeIdentity.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns an `AssociativeIdentity` for an `ImmutableArray`. 3 | * 4 | * @tsplus static ImmutableArray.Ops getAssociativeIdentity 5 | */ 6 | export function getAssociativeIdentity(): AssociativeIdentity> { 7 | return AssociativeIdentity(ImmutableArray.empty(), (a, b) => a.concat(b)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => ImmutableArray({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops Applicative 3 | */ 4 | export const Applicative = DSL.getApplicativeF(ImmutableArray.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Apply.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Apply" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Apply 5 | */ 6 | export const Apply = HKT.instance>({ 7 | ...ImmutableArray.Covariant, 8 | ...ImmutableArray.AssociativeBoth 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: ImmutableArray.$.zip 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (ffa) => ffa.flatten 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Compact.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Compact" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Compact 5 | */ 6 | export const Compact = HKT.instance>({ 7 | compact: (fa) => fa.compact 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: ImmutableArray.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Extend.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Extend" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops extend 5 | */ 6 | export const Extend = HKT.instance>({ 7 | extend: ImmutableArray.$.extend 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Filter.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Filter" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Filter 5 | */ 6 | export const Filter = HKT.instance>({ 7 | filter: ImmutableArray.$.filter 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/FilterMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterMap" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops FilterMap 5 | */ 6 | export const FilterMap = HKT.instance>({ 7 | filterMap: ImmutableArray.$.collect 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/FilterMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterMapWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops FilterMapWithIndex 5 | */ 6 | export const FilterMapWithIndex = HKT.instance>({ 7 | filterMapWithIndex: ImmutableArray.$.collectWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/FilterWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FilterWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops FilterWithIndex 5 | */ 6 | export const FilterWithIndex = HKT.instance>({ 7 | filterWithIndex: ImmutableArray.$.filterWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Filterable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Filterable" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Filterable 5 | */ 6 | export const Filterable = HKT.instance>({ 7 | ...ImmutableArray.Filter, 8 | ...ImmutableArray.FilterMap, 9 | ...ImmutableArray.Partition, 10 | ...ImmutableArray.PartitionMap 11 | }) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/FoldMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMap" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops FoldMap 5 | */ 6 | export const FoldMap = HKT.instance>({ 7 | foldMap: (M) => (f) => (fa) => fa.foldMap(M, f) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/FoldMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMapWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops FoldMapWithIndex 5 | */ 6 | export const FoldMapWithIndex = HKT.instance>({ 7 | foldMapWithIndex: (M) => (f) => (fa) => fa.foldMapWithIndex(M, (a, i) => f(i, a)) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Foldable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Foldable" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Foldable 5 | */ 6 | export const Foldable = HKT.instance>({ 7 | ...ImmutableArray.FoldMap, 8 | ...ImmutableArray.Reduce, 9 | ...ImmutableArray.ReduceRight 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/ForEach.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEach" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops ForEach 5 | */ 6 | export const ForEachImmutableArray = HKT.instance>({ 7 | ...ImmutableArray.Covariant, 8 | forEachF: ImmutableArray.forEachF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/ForEachWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEachWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops ForEachWithIndex 5 | */ 6 | export const ForEachWithIndex = HKT.instance>({ 7 | ...ImmutableArray.Covariant, 8 | forEachWithIndexF: ImmutableArray.forEachWithIndexF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...ImmutableArray.Any, 8 | ...ImmutableArray.Covariant, 9 | ...ImmutableArray.AssociativeFlatten 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Partition.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Partition" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Partition 5 | */ 6 | export const Partition = HKT.instance>({ 7 | partition: ImmutableArray.$.partition 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/PartitionMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionMap" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops PartitionMap 5 | */ 6 | export const PartitionMap = HKT.instance>({ 7 | partitionMap: ImmutableArray.$.partitionMap 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/PartitionMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionMapWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops PartitionMapWithIndex 5 | */ 6 | export const PartitionMapWithIndex = HKT.instance< 7 | P.PartitionMapWithIndex 8 | >({ 9 | partitionMapWithIndex: ImmutableArray.$.partitionMapWithIndex 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/PartitionWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/PartitionWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops PartitionWithIndex 5 | */ 6 | export const PartitionWithIndex = HKT.instance>({ 7 | partitionWithIndex: ImmutableArray.$.partitionWithIndex 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Reduce.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Reduce" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Reduce 5 | */ 6 | export const Reduce = HKT.instance>({ 7 | reduce: (b, f) => (fa) => fa.reduce(b, f) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/ReduceRight.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceRight" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops ReduceRight 5 | */ 6 | export const ReduceRight = HKT.instance>({ 7 | reduceRight: (b, f) => (fa) => fa.array.reduceRight((b, a) => f(a, b), b) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/ReduceWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops ReduceWithIndex 5 | */ 6 | export const ReduceWithIndex = HKT.instance>({ 7 | reduceWithIndex: (b, f) => (fa) => fa.reduceWithIndex(b, (b, a, i) => f(i, b, a)) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Separate.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Separate" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops separate 5 | */ 6 | export const Separate = HKT.instance>({ 7 | separate: (fa) => fa.separate 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Wiltable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Wiltable" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Wiltable 5 | */ 6 | export const Wiltable = HKT.instance>({ 7 | separateF: ImmutableArray.separateF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/WiltableWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/WiltableWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops WiltableWithIndex 5 | */ 6 | export const WiltableWithIndex = HKT.instance>({ 7 | separateWithIndexF: ImmutableArray.separateWithIndexF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/Witherable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Witherable" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops Witherable 5 | */ 6 | export const Witherable = HKT.instance>({ 7 | compactF: ImmutableArray.compactF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/instances/WitherableWithIndex.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/WitherableWithIndex" 2 | 3 | /** 4 | * @tsplus static ImmutableArray.Ops WitherableWithIndex 5 | */ 6 | export const WitherableWithIndex = HKT.instance>({ 7 | compactWithIndexF: ImmutableArray.compactWithIndexF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/isEmpty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` if the array contains no elements, otherwise returns `false`. 3 | * 4 | * @tsplus getter ImmutableArray isEmpty 5 | */ 6 | export function isEmpty(self: ImmutableArray): boolean { 7 | return self.array.length === 0 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/isNonEmpty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus fluent ImmutableArray isNonEmpty 3 | */ 4 | export function isNonEmpty(self: ImmutableArray): self is NonEmptyImmutableArray { 5 | return self.array.length > 0 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/make.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Ops __call 3 | * @tsplus static ImmutableArray.Ops make 4 | */ 5 | export function make(...as: A): ImmutableArray { 6 | return new ImmutableArray(as) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableArray.Aspects map 3 | * @tsplus pipeable ImmutableArray map 4 | */ 5 | export function map(f: (a: A, k: number) => B) { 6 | return (self: ImmutableArray): ImmutableArray => 7 | new ImmutableArray(self.array.map((a, i) => f(a, i))) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/partition.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Separate elements based on a predicate. 3 | * 4 | * @tsplus static ImmutableArray.Aspects partition 5 | * @tsplus pipeable ImmutableArray partition 6 | */ 7 | export function partition(f: Predicate) { 8 | return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => 9 | self.partitionWithIndex((_, a) => f(a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/size.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter ImmutableArray size 3 | */ 4 | export function size(self: ImmutableArray) { 5 | return self.array.length 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/sort.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sort the elements of an `ImmutableArray` in increasing order. 3 | * 4 | * @tsplus static ImmutableArray.Aspects sort 5 | * @tsplus pipeable ImmutableArray sort 6 | */ 7 | export function sort(O: Ord) { 8 | return (self: ImmutableArray): ImmutableArray => 9 | new ImmutableArray([...self].sort((x, y) => O.compare(x, y))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableArray/toCollection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter ImmutableArray toCollection 3 | */ 4 | export function toCollection(self: ImmutableArray): Collection { 5 | return self 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/copy.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copies each element of an `ImmutableMap` into a new `ImmutableMap`. 3 | * 4 | * @tsplus getter ImmutableMap copy 5 | */ 6 | export function copy(self: ImmutableMap): ImmutableMap { 7 | const map = new Map() 8 | for (const [key, value] of self.internalMap) { 9 | map.set(key, value) 10 | } 11 | return new ImmutableMap(map) 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a new empty `ImmutableMap`. 3 | * 4 | * @tsplus static ImmutableMap.Ops empty 5 | */ 6 | export function empty(): ImmutableMap { 7 | return new ImmutableMap(new Map()) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/from.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a new `ImmutableMap` from a set of entries. 3 | * 4 | * @tsplus static ImmutableMap.Ops from 5 | */ 6 | export function from( 7 | entries: Collection 8 | ): ImmutableMap { 9 | const map = new Map() 10 | for (const [key, value] of entries) { 11 | map.set(key, value) 12 | } 13 | return new ImmutableMap(map) 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/has.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` if the map contains the specified key, otherwise returns 3 | * `false`. 4 | * 5 | * @tsplus static ImmutableMap.Aspects has 6 | * @tsplus pipeable ImmutableMap has 7 | */ 8 | export function has(key: K) { 9 | return (self: ImmutableMap): boolean => self.internalMap.has(key) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/isEmpty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` if the map contains no entries, otherwise returns `false`. 3 | * 4 | * @tsplus getter ImmutableMap isEmpty 5 | */ 6 | export function isEmpty(self: ImmutableMap): boolean { 7 | return self.internalMap.size === 0 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableMap/size.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the number of elements contained within the map. 3 | * 4 | * @tsplus getter ImmutableMap size 5 | */ 6 | export function size(self: ImmutableMap): number { 7 | return self.internalMap.size 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/append.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableQueue.Aspects append 3 | * @tsplus pipeable ImmutableQueue append 4 | */ 5 | export function append(value: A) { 6 | return (self: ImmutableQueue): ImmutableQueue => self.appendAll(List(value)) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/empty.ts: -------------------------------------------------------------------------------- 1 | import { ImmutableQueueInternal } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" 2 | 3 | /** 4 | * @tsplus static ImmutableQueue.Ops empty 5 | */ 6 | export function empty(): ImmutableQueue { 7 | return new ImmutableQueueInternal(List.nil()) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/from.ts: -------------------------------------------------------------------------------- 1 | import { ImmutableQueueInternal } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" 2 | 3 | /** 4 | * @tsplus static ImmutableQueue.Ops from 5 | */ 6 | export function from(collection: Collection): ImmutableQueue { 7 | return new ImmutableQueueInternal(List.from(collection)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/head.ts: -------------------------------------------------------------------------------- 1 | import { concreteImmutableQueue } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" 2 | 3 | /** 4 | * @tsplus getter ImmutableQueue head 5 | */ 6 | export function head(self: ImmutableQueue): Maybe { 7 | concreteImmutableQueue(self) 8 | return self.backingList.head 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/make.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static ImmutableQueue.Ops __call 3 | * @tsplus static ImmutableQueue.Ops make 4 | */ 5 | export function make(...values: As): ImmutableQueue { 6 | return ImmutableQueue.from(values) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/single.ts: -------------------------------------------------------------------------------- 1 | import { ImmutableQueueInternal } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" 2 | 3 | /** 4 | * @tsplus static ImmutableQueue.Ops single 5 | */ 6 | export function single(value: A): ImmutableQueue { 7 | return new ImmutableQueueInternal(List.cons(value, List.nil())) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ImmutableQueue/size.ts: -------------------------------------------------------------------------------- 1 | import { concreteImmutableQueue } from "@tsplus/stdlib/collections/ImmutableQueue/_internal/ImmutableQueueInternal" 2 | 3 | /** 4 | * @tsplus getter ImmutableQueue size 5 | */ 6 | export function size(self: ImmutableQueue): number { 7 | concreteImmutableQueue(self) 8 | return self.backingList.length 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the empty `List` 3 | * 4 | * @tsplus static List.Ops empty 5 | */ 6 | export function empty(): List { 7 | return List.nil() 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/exists.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static List.Aspects exists 3 | * @tsplus pipeable List exists 4 | */ 5 | export function exists(p: Predicate) { 6 | return (self: List): boolean => { 7 | let these = self 8 | while (!these.isNil()) { 9 | if (p(these.head)) { 10 | return true 11 | } 12 | these = these.tail 13 | } 14 | return false 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/forEach.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static List.Aspects forEach 3 | * @tsplus pipeable List forEach 4 | */ 5 | export function forEach(f: (a: A) => U) { 6 | return (self: List): void => { 7 | let these = self 8 | while (!these.isNil()) { 9 | f(these.head) 10 | these = these.tail 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/head.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List head 3 | */ 4 | export function head(self: List): Maybe { 5 | return self.isNil() ? Maybe.none : Maybe.some(self.head) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/last.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List last 3 | */ 4 | export function last(self: List): Maybe { 5 | return self.isNil() ? Maybe.none : Maybe.some(self.unsafeLast!) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static List.Aspects reduce 3 | * @tsplus pipeable List reduce 4 | */ 5 | export function reduce(b: B, f: (b: B, a: A) => B) { 6 | return (self: List): B => { 7 | let acc = b 8 | let these = self 9 | while (!these.isNil()) { 10 | acc = f(acc, these.head) 11 | these = these.tail 12 | } 13 | return acc 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/reverse.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reverses a `List`, returning a new `List` 3 | * 4 | * @tsplus getter List reverse 5 | */ 6 | export function reverse(self: List): List { 7 | let result = List.empty() 8 | let these = self 9 | while (!these.isNil()) { 10 | result = result.prepend(these.head) 11 | these = these.tail 12 | } 13 | return result 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/splitAt.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns two splits of this list at the specified index. 3 | * 4 | * @tsplus static List.Aspects splitAt 5 | * @tsplus pipeable List splitAt 6 | */ 7 | export function splitAt(n: number) { 8 | return (self: List): readonly [List, List] => [self.take(n).toList, self.drop(n)] 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/tail.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List tail 3 | */ 4 | export function tail(self: List): Maybe> { 5 | return self.isNil() ? Maybe.none : Maybe.some(self.tail) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/toCollection.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List toCollection 3 | */ 4 | export function toCollection(self: List): Collection { 5 | return self 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/unsafeHead.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List unsafeHead 3 | */ 4 | export function unsafeHead(self: List): A | undefined { 5 | if (self.isNil()) { 6 | return undefined 7 | } 8 | return self.head 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/unsafeLast.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List unsafeLast 3 | */ 4 | export function unsafeLast(self: List): A | undefined { 5 | if (self.isNil()) { 6 | return undefined 7 | } 8 | let these = self 9 | let scout = self.tail 10 | while (!scout.isNil()) { 11 | these = scout 12 | scout = scout.tail 13 | } 14 | return these.head 15 | } 16 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/List/unsafeTail.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter List unsafeTail 3 | */ 4 | export function unsafeTail(self: List): List | undefined { 5 | if (self.isNil()) { 6 | return undefined 7 | } 8 | return self.tail 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/getAssociative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static NonEmptyImmutableArray.Ops getAssociative 3 | */ 4 | export function getAssociative(): Associative> { 5 | return Associative((x, y) => x + y) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/getEquivalence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static NonEmptyImmutableArray.Ops getEquivalence 3 | */ 4 | export function getEquivalence(E: Equivalence): Equivalence> { 5 | return Equivalence((xs, ys) => 6 | xs === ys || 7 | (xs.array.length === ys.array.length && xs.array.every((x, i) => E.equals(x, ys.array[i]!))) 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/getShow.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static NonEmptyImmutableArray.Ops getShow 3 | */ 4 | export function getShow(S: Show): Show> { 5 | return Show((as) => `NonEmptyImmutableArray(${as.array.map(S.show).join(", ")})`) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/head.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Retrieves the first element of the array. 3 | * 4 | * @tsplus getter NonEmptyImmutableArray head 5 | */ 6 | export function head(self: NonEmptyImmutableArray): A { 7 | return self.array[0]! 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/init.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Retrieves all elements of the array except the last element. 3 | * 4 | * @tsplus getter NonEmptyImmutableArray init 5 | */ 6 | export function init(self: NonEmptyImmutableArray): ImmutableArray { 7 | return new ImmutableArray(self.array.slice(0, -1)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/last.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Retrieves the last element of the array. 3 | * 4 | * @tsplus getter NonEmptyImmutableArray last 5 | */ 6 | export function last(self: NonEmptyImmutableArray): A { 7 | return self.array[self.array.length - 1]! 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static NonEmptyImmutableArray.Aspects map 3 | * @tsplus pipeable NonEmptyImmutableArray map 4 | */ 5 | export function map(f: (a: A, i: number) => B) { 6 | return (self: NonEmptyImmutableArray): NonEmptyImmutableArray => 7 | new ImmutableArray(self.array.map((a, i) => f(a, i)) as any) as NonEmptyImmutableArray 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/NonEmptyImmutableArray/tail.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Retrieves all elements of the array except for the first. 3 | * 4 | * @tsplus getter NonEmptyImmutableArray tail 5 | */ 6 | export function tail(self: NonEmptyImmutableArray): ImmutableArray { 7 | return new ImmutableArray(self.array.slice(1)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ParSeq/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flattens a collection of collections of events into a single collection 3 | * of events. 4 | * 5 | * @tsplus getter ParSeq flatten 6 | */ 7 | export function flatten(self: ParSeq>): ParSeq { 8 | return self.flatMap(identity) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/ParSeq/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms the type of events in this collection of events with the 3 | * specified function. 4 | * 5 | * @tsplus static ParSeq.Aspects map 6 | * @tsplus pipeable ParSeq map 7 | */ 8 | export function map(f: (a: A) => B) { 9 | return (self: ParSeq): ParSeq => self.flatMap((a) => ParSeq.single(f(a))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/RedBlackTree/empty.ts: -------------------------------------------------------------------------------- 1 | import { RedBlackTreeInternal } from "@tsplus/stdlib/collections/RedBlackTree/_internal/RedBlackTreeInternal" 2 | 3 | /** 4 | * @tsplus static RedBlackTree.Ops empty 5 | */ 6 | export function empty( 7 | ord: Ord 8 | ): RedBlackTree { 9 | return new RedBlackTreeInternal(ord, undefined) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/RedBlackTree/has.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Finds the item with key if it exists. 3 | * 4 | * @tsplus static RedBlackTree.Aspects has 5 | * @tsplus pipeable RedBlackTree has 6 | */ 7 | export function has(key: K) { 8 | return (self: RedBlackTree): boolean => self.findFirst(key).isSome() 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/RedBlackTree/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reduce a state over the map entries. 3 | * 4 | * @tsplus static RedBlackTree.Aspects reduce 5 | * @tsplus pipeable RedBlackTree reduce 6 | */ 7 | export function reduce(z: Z, f: (z: Z, v: V) => Z) { 8 | return (self: RedBlackTree): Z => self.reduceWithIndex(z, (z1, _, v) => f(z1, v)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/RedBlackTree/size.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the length of the tree. 3 | * 4 | * @tsplus getter RedBlackTree size 5 | */ 6 | export function size(self: RedBlackTree): number { 7 | return self.root?.count ?? 0 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Set.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Set/*.ts, prefix: "@tsplus/stdlib/collections"} 2 | export * from "@tsplus/stdlib/collections/Set/definition" 3 | export * from "@tsplus/stdlib/collections/Set/empty" 4 | export * from "@tsplus/stdlib/collections/Set/from" 5 | export * from "@tsplus/stdlib/collections/Set/make" 6 | // codegen:end 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Set/definition.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | /** 3 | * @tsplus type Set 4 | */ 5 | export interface Set extends Collection {} 6 | /** 7 | * @tsplus type Set.Ops 8 | */ 9 | export interface SetConstructor { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Set/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Set.Ops empty 3 | */ 4 | export function empty(): Set { 5 | return new Set() 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Set/from.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Set.Ops from 3 | * @tsplus getter Collection toSet 4 | */ 5 | export function from(data: Collection): Set { 6 | return new Set(data) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Set/make.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constructs a new `Set`. 3 | * 4 | * @tsplus static Set.Ops __call 5 | * @tsplus static Set.Ops make 6 | */ 7 | export function make(...data: As): Set { 8 | return Set.from(data) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/empty.ts: -------------------------------------------------------------------------------- 1 | import { SortedMapInternal } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus static SortedMap.Ops empty 5 | */ 6 | export function empty(ord: Ord): SortedMap { 7 | return new SortedMapInternal(RedBlackTree.empty(ord)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/entries.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter SortedMap entries 3 | */ 4 | export function entries(self: SortedMap): Iterator { 5 | return self[Symbol.iterator]() 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/get.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus static SortedMap.Aspects get 5 | * @tsplus pipeable SortedMap get 6 | */ 7 | export function get(key: K) { 8 | return (self: SortedMap): Maybe => { 9 | concreteSortedMap(self) 10 | return self.tree.findFirst(key) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/getOrd.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus getter SortedMap getOrd 5 | */ 6 | export function getOrd(self: SortedMap): Ord { 7 | concreteSortedMap(self) 8 | return self.tree.ord 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/has.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedMap.Aspects has 3 | * @tsplus pipeable SortedMap has 4 | */ 5 | export function has(key: K) { 6 | return (self: SortedMap): boolean => { 7 | return self.get(key).isSome() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/headMaybe.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus getter SortedMap headMaybe 5 | */ 6 | export function headMaybe(self: SortedMap): Maybe { 7 | concreteSortedMap(self) 8 | return self.tree.first 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/isEmpty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter SortedMap isEmpty 3 | */ 4 | export function isEmpty(self: SortedMap): boolean { 5 | return self.size === 0 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/isNonEmpty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter SortedMap isNonEmpty 3 | */ 4 | export function isNonEmpty(self: SortedMap): boolean { 5 | return !self.isEmpty 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/keys.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus getter SortedMap keys 5 | */ 6 | export function keys(self: SortedMap): IterableIterator { 7 | concreteSortedMap(self) 8 | return self.tree.keys() 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/make.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedMap.Ops __call 3 | * @tsplus static SortedMap.Ops make 4 | */ 5 | export function make( 6 | ord: Ord 7 | ): (...entries: Entries) => SortedMap< 8 | K, 9 | Entries[number] extends (readonly [any, infer V]) ? V : never 10 | > { 11 | return (...entries) => SortedMap.from(ord)(entries) 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedMap.Aspects map 3 | * @tsplus pipeable SortedMap map 4 | */ 5 | export function map(f: (v: V) => B) { 6 | return (self: SortedMap): SortedMap => { 7 | return self.mapWithIndex((_, v: V) => f(v)) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/mapWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedMap.Aspects mapWithIndex 3 | * @tsplus pipeable SortedMap mapWithIndex 4 | */ 5 | export function mapWithIndex(f: (k: K, v: V) => A) { 6 | return (self: SortedMap): SortedMap => 7 | self.reduceWithIndex(SortedMap.empty(self.getOrd), (b, k, v) => b.set(k, f(k, v))) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedMap.Aspects reduce 3 | * @tsplus pipeable SortedMap reduce 4 | */ 5 | export function reduce(z: Z, f: (acc: Z, v: V) => Z) { 6 | return (self: SortedMap): Z => self.reduceWithIndex(z, (acc, _, v) => f(acc, v)) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/size.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus getter SortedMap size 5 | */ 6 | export function size(self: SortedMap): number { 7 | concreteSortedMap(self) 8 | return self.tree.size 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedMap/values.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedMap } from "@tsplus/stdlib/collections/SortedMap/_internal/SortedMapInternal" 2 | 3 | /** 4 | * @tsplus getter SortedMap values 5 | */ 6 | export function values(self: SortedMap): IterableIterator { 7 | concreteSortedMap(self) 8 | return self.tree.values() 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/derive.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus derive SortedSet<_> 10 3 | */ 4 | export function deriveSortedSet( 5 | ...[ord]: [Ord] 6 | ): SortedSet { 7 | return SortedSet.empty(ord) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/empty.ts: -------------------------------------------------------------------------------- 1 | import { SortedSetInternal } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" 2 | 3 | /** 4 | * @tsplus static SortedSet.Ops empty 5 | */ 6 | export function empty(ord: Ord): SortedSet { 7 | return new SortedSetInternal(RedBlackTree.empty(ord)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/forAll.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` if all elements match the specified predicate, otherwise 3 | * returns `false`. 4 | * 5 | * @tsplus static SortedSet.Aspects forAll 6 | * @tsplus pipeable SortedSet forAll 7 | */ 8 | export function forAll(f: Predicate) { 9 | return (self: SortedSet): boolean => !self.forAny((a) => !f(a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/getOrd.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedSet } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" 2 | 3 | /** 4 | * @tsplus getter SortedSet getOrd 5 | */ 6 | export function getOrd(self: SortedSet): Ord { 7 | concreteSortedSet(self) 8 | return self.keyTree.ord 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/has.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedSet } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" 2 | 3 | /** 4 | * @tsplus static SortedSet.Aspects has 5 | * @tsplus pipeable SortedSet has 6 | */ 7 | export function has(value: A) { 8 | return (self: SortedSet): boolean => { 9 | concreteSortedSet(self) 10 | return self.keyTree.has(value) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/make.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static SortedSet.Ops __call 3 | * @tsplus static SortedSet.Ops make 4 | */ 5 | export function make( 6 | ord: Ord 7 | ): (...entries: Array) => SortedSet { 8 | return (...entries: Array) => SortedSet.from(ord)(entries) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/size.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedSet } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" 2 | 3 | /** 4 | * Calculate the number of keys in the set. 5 | * 6 | * @tsplus getter SortedSet size 7 | */ 8 | export function size(self: SortedSet): number { 9 | concreteSortedSet(self) 10 | return self.keyTree.size 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/toggle.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * If element is present in the set then it will be removed, otherwise it will 3 | * be added. 4 | * 5 | * @tsplus static SortedSet.Aspects toggle 6 | * @tsplus pipeable SortedSet toggle 7 | */ 8 | export function toggle(value: A) { 9 | return (self: SortedSet): SortedSet => 10 | self.has(value) ? self.remove(value) : self.add(value) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/SortedSet/values.ts: -------------------------------------------------------------------------------- 1 | import { concreteSortedSet } from "@tsplus/stdlib/collections/SortedSet/_internal/SortedSetInternal" 2 | 3 | /** 4 | * @tsplus getter SortedSet values 5 | */ 6 | export function values(self: SortedSet): IterableIterator { 7 | concreteSortedSet(self) 8 | return self.keyTree.keys() 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/corresponds.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects corresponds 3 | * @tsplus pipeable Tree corresponds 4 | */ 5 | export function corresponds( 6 | that: Tree, 7 | f: (a: A, b: B) => boolean 8 | ) { 9 | return (self: Tree): boolean => ( 10 | f(self.value, that.value) && 11 | self.forest.corresponds(that.forest, (a, b) => a.corresponds(b, f)) 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/duplicate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus getter Tree duplicate 3 | */ 4 | export function duplicate_(self: Tree): Tree> { 5 | return self.extend(identity) 6 | } 7 | /** 8 | * @tsplus static Tree.Aspects duplicate 9 | */ 10 | export const duplicate = Pipeable(duplicate_) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/equals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus pipeable-operator Tree == 3 | * @tsplus static Tree.Aspects equals 4 | * @tsplus pipeable Tree equals 5 | */ 6 | export function equals(that: Tree) { 7 | return (self: Tree): boolean => self.corresponds(that, Equals.equals) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert a `Tree` into a `Tree` using a function from `Tree => B` 3 | * applied to each node in the Tree. 4 | * 5 | * @tsplus static Tree.Aspects extend 6 | * @tsplus pipeable Tree extend 7 | */ 8 | export function extend(f: (wa: Tree) => B) { 9 | return (self: Tree): Tree => Tree(f(self), self.forest.map((_) => _.extend(f))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flatten a `Tree>` into `a Tree` 3 | * 4 | * @tsplus getter Tree flatten 5 | */ 6 | export function flatten(self: Tree>): Tree { 7 | return self.flatMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/fold.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects fold 3 | * @tsplus pipeable Tree fold 4 | */ 5 | export function fold_(f: (a: A, bs: Chunk) => B) { 6 | return (self: Tree): B => f(self.value, self.forest.map((_) => _.fold(f))) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/foldMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects foldMap 3 | * @tsplus pipeable Tree foldMap 4 | */ 5 | export function foldMap(M: AssociativeIdentity, f: (a: A) => M) { 6 | return (self: Tree): M => self.reduce(M.identity, (m, a) => M.combine(m, f(a))) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/forEach.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Iterate over the Tree in breadth-first order, applying `f` 3 | * 4 | * @tsplus static Tree.Aspects forEach 5 | * @tsplus pipeable Tree forEach 6 | */ 7 | export function forEach(f: (a: A) => U) { 8 | return (self: Tree): void => { 9 | f(self.value) 10 | self.forest.map((a: Tree) => a.forEach(f)) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/getShow.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Ops getShow 3 | */ 4 | export function getShow(S: Show): Show> { 5 | return Show(show_) 6 | function show_(tree: Tree): string { 7 | return `Tree(${S.show(tree.value)}, ${tree.forest.map(show_)})` 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => Tree({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Ops Applicative 3 | */ 4 | export const Applicative = DSL.getApplicativeF(Tree.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Apply.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Apply" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Apply 5 | */ 6 | export const Apply = HKT.instance>({ 7 | ...Tree.AssociativeBoth, 8 | ...Tree.Covariant 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static Tree.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: Tree.$.zip 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static Tree.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (ffa) => ffa.flatten 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: Tree.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Extend.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Extend" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Extend 5 | */ 6 | export const Extend = HKT.instance>({ 7 | extend: Tree.$.extend 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/FoldMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMap" 2 | 3 | /** 4 | * @tsplus static Tree.Ops FoldMap 5 | */ 6 | export const FoldMap = HKT.instance>({ 7 | foldMap: (M) => (f) => (fa) => fa.foldMap(M, f) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/ForEach.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEach" 2 | 3 | /** 4 | * @tsplus static Tree.Ops ForEach 5 | */ 6 | export const ForEach = HKT.instance>({ 7 | ...Tree.Covariant, 8 | forEachF: Tree.forEachF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...Tree.Any, 8 | ...Tree.Covariant, 9 | ...Tree.AssociativeFlatten 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/instances/Reduce.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Reduce" 2 | 3 | /** 4 | * @tsplus static Tree.Ops Reduce 5 | */ 6 | export const Reduce = HKT.instance>({ 7 | reduce: Tree.$.reduce 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects map 3 | * @tsplus pipeable Tree map 4 | */ 5 | export function map(f: (a: A) => B) { 6 | return (self: Tree): Tree => Tree(f(self.value), self.forest.map((fa) => fa.map(f))) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects reduce 3 | * @tsplus pipeable Tree reduce 4 | */ 5 | export function reduce(b: B, f: (b: B, a: A) => B) { 6 | return (self: Tree): B => self.forest.reduce(f(b, self.value), (s, a) => a.reduce(s, f)) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/zip.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects zip 3 | * @tsplus pipeable Tree zip 4 | */ 5 | export function zip(that: Tree) { 6 | return (self: Tree): Tree => self.zipWith(that, (a, b) => [a, b]) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/Tree/zipWith.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Tree.Aspects zipWith 3 | * @tsplus pipeable Tree zipWith 4 | */ 5 | export function zipWith(that: Tree, f: (a: A, b: B) => C) { 6 | return (self: Tree): Tree => { 7 | const value = f(self.value, that.value) 8 | return Tree(value, self.forest.zipWith(that.forest, (a, b) => a.zipWith(b, f))) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableHashMap/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a new empty `MutableHashMap`. 3 | * 4 | * @tsplus static MutableHashMap.Ops empty 5 | */ 6 | export function empty() { 7 | return new MutableHashMap() 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableHashMap/has.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static MutableHashMap.Aspects has 3 | * @tsplus pipeable MutableHashMap has 4 | */ 5 | export function has(key: K) { 6 | return (self: MutableHashMap): boolean => self.get(key).isSome() 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableHashSet/empty.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a new empty `MutableHashSet`. 3 | * 4 | * @tsplus static MutableHashSet.Ops empty 5 | */ 6 | export function empty(): MutableHashSet { 7 | return new MutableHashSet() 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableHashSet/from.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Construct a new `MutableHashSet` from a `Collection` of values 3 | * 4 | * @tsplus static MutableHashSet.Ops from 5 | */ 6 | export function from(elements: Collection): MutableHashSet { 7 | const set = MutableHashSet.empty() 8 | for (const value of elements) { 9 | set.add(value) 10 | } 11 | return set 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableQueue.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./MutableQueue/*.ts, prefix: "@tsplus/stdlib/collections/mutable"} 2 | export * from "@tsplus/stdlib/collections/mutable/MutableQueue/bounded" 3 | export * from "@tsplus/stdlib/collections/mutable/MutableQueue/definition" 4 | export * from "@tsplus/stdlib/collections/mutable/MutableQueue/unbounded" 5 | // codegen:end 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableQueue/bounded.ts: -------------------------------------------------------------------------------- 1 | import { Bounded } from "@tsplus/stdlib/collections/mutable/MutableQueue/_internal/Bounded" 2 | 3 | /** 4 | * Creates a new bounded `MutableQueue`. 5 | * 6 | * @tsplus static MutableQueue.Ops bounded 7 | */ 8 | export function bounded(n: number): MutableQueue { 9 | return new Bounded(n) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/mutable/MutableQueue/unbounded.ts: -------------------------------------------------------------------------------- 1 | import { Unbounded } from "@tsplus/stdlib/collections/mutable/MutableQueue/_internal/Unbounded" 2 | 3 | /** 4 | * Creates a new unbounded `MutableQueue`. 5 | * 6 | * @tsplus static MutableQueue.Ops unbounded 7 | */ 8 | export function unbounded(): MutableQueue { 9 | return new Unbounded() 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/collections/weak.ts: -------------------------------------------------------------------------------- 1 | export * as weakMapIterable from "@tsplus/stdlib/collections/weak/IterableWeakMap" 2 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/AtomicBoolean.ts: -------------------------------------------------------------------------------- 1 | import { AtomicReference } from "@tsplus/stdlib/data/AtomicReference" 2 | 3 | export class AtomicBoolean extends AtomicReference { 4 | constructor(b: boolean) { 5 | super(b) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Differ.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Differ/*.ts, prefix: "@tsplus/stdlib/data"} 2 | export * from "@tsplus/stdlib/data/Differ/definition" 3 | export * from "@tsplus/stdlib/data/Differ/operations" 4 | export * from "@tsplus/stdlib/data/Differ/OrPatch" 5 | // codegen:end 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Differ/OrPatch.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./OrPatch/*.ts, prefix: "@tsplus/stdlib/data/Differ"} 2 | export * from "@tsplus/stdlib/data/Differ/OrPatch/definition" 3 | export * from "@tsplus/stdlib/data/Differ/OrPatch/operations" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/ap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Classic Applicative. 3 | * 4 | * @tsplus static Either.Aspects ap 5 | * @tsplus pipeable Either ap 6 | */ 7 | export function ap(that: Either) { 8 | return (self: Either B>): Either => 9 | self.isLeft() ? self : that.isLeft() ? that : Either.right(self.right(that.right)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/catchAll.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Executes the specified `Either` if it is a `Right`, otherwise executes 3 | * `onLeft`. 4 | * 5 | * @tsplus static Either.Aspects catchAll 6 | * @tsplus pipeable Either catchAll 7 | */ 8 | export function catchAll(onLeft: (e: E) => Either) { 9 | return (self: Either): Either => self.isLeft() ? onLeft(self.left) : self 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/compact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Compact types Either | Either = Either 3 | * 4 | * @tsplus static Either.Ops compact 5 | * @tsplus macro identity 6 | */ 7 | export function compact>( 8 | _: E 9 | ): [E] extends [Either] ? Either : E { 10 | return _ as any 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/dsl/branch.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops if 3 | */ 4 | export const branch = DSL.conditionalF() 5 | 6 | /** 7 | * @tsplus static Either.Ops if_ 8 | */ 9 | export const branch_ = DSL.conditionalF_() 10 | 11 | export { branch as if, branch_ as if_ } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/dsl/gen.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops gen 3 | */ 4 | export const gen = DSL.genF(Either.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/dsl/sequence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops sequence 3 | */ 4 | export const sequence = ForEach.sequenceF(Either.ForEach) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/dsl/struct.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops struct 3 | */ 4 | export const struct = DSL.structF(Either.Applicative) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/dsl/tuple.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops tuple 3 | */ 4 | export const tuple = DSL.tupleF(Either.Applicative) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/duplicate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Self embed `Either` into `Either>`. 3 | * 4 | * @tsplus getter Either duplicate 5 | */ 6 | export function duplicate(self: Either): Either> { 7 | return self.extend(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/exists.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `false` if `Left` or returns the result of the application of the 3 | * given predicate to the `Right` value. 4 | * 5 | * @tsplus static Either.Aspects exists 6 | * @tsplus pipeable Either exists 7 | */ 8 | export function exists(f: Predicate) { 9 | return (self: Either): boolean => self.isLeft() ? false : f(self.right) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply `Either => B` in case self is right returning `Either`. 3 | * 4 | * @tsplus static Either.Aspects extend 5 | * @tsplus pipeable Either extend 6 | */ 7 | export function extend(f: (either: Either) => B) { 8 | return (self: Either): Either => self.isLeft() ? self : Either.right(f(self)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flatten nested `Either>` into `Either`. 3 | * 4 | * @tsplus getter Either flatten 5 | */ 6 | export function flatten(self: Either>): Either { 7 | return self.flatMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/foldMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Folds an `AssociativeIdentity` through an `Either`. 3 | * 4 | * @tsplus static Either.Aspects foldMap 5 | * @tsplus pipeable Either foldMap 6 | */ 7 | export function foldMap(I: AssociativeIdentity, f: (a: A) => M) { 8 | return (self: Either): M => self.isLeft() ? I.identity : f(self.right) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/fromMaybe.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Construct `Either` from `Maybe` constructing `E` with `onNone`. 3 | * 4 | * @tsplus static Either.Ops fromMaybe 5 | */ 6 | export function fromMaybe(maybe: Maybe, onNone: LazyArg): Either { 7 | return maybe.isNone() ? Either.left(onNone()) : Either.right(maybe.value) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getAssociative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get `Associative` for `Either` given `Associative` of `A`. 3 | * 4 | * @tsplus static Either.Ops getAssociative 5 | */ 6 | export function getAssociative(S: Associative): Associative> { 7 | return Associative((x, y) => 8 | y.isLeft() ? x : x.isLeft() ? y : Either.right(S.combine(x.right, y.right)) 9 | ) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getCompact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get a `Compact` instance for an `Either` given an 3 | * `AssociativeIdentity`. 4 | * 5 | * @tsplus static Either.Ops getCompact 6 | */ 7 | export function getCompact(M: AssociativeIdentity) { 8 | const compact = Either.$.compactMaybe(M) 9 | return HKT.instance>>({ 10 | compact 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getEquivalence.ts: -------------------------------------------------------------------------------- 1 | export function getEquivalence( 2 | EE: Equivalence, 3 | EA: Equivalence 4 | ): Equivalence> { 5 | return Equivalence((x, y) => 6 | x === y || 7 | (x.isLeft() ? 8 | y.isLeft() && EE.equals(x.left, y.left) : 9 | y.isRight() && EA.equals(x.right, y.right)) 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getOrElse.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get `A` or in case self is left return `onLeft` result. 3 | * 4 | * @tsplus static Either.Aspects getOrElse 5 | * @tsplus pipeable Either getOrElse 6 | */ 7 | export function getOrElse(onLeft: (e: E) => A) { 8 | return (self: Either): A | B => self.isLeft() ? onLeft(self.left) : self.right 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getSeparate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get a `Separate` instance for an `Either` given an 3 | * `AssociativeIdentity`. 4 | * 5 | * @tsplus static Either.Ops getSeparate 6 | */ 7 | export function getSeparate(M: AssociativeIdentity) { 8 | const separate = Either.$.separate(M) 9 | return HKT.instance>>({ 10 | separate 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getShow.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops getShow 3 | */ 4 | export function getShow(SE: Show, SA: Show): Show> { 5 | return Show((either) => 6 | either.isLeft() ? `Left(${SE.show(either.left)})` : `Right(${SA.show(either.right)})` 7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getValidationApplicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Either.Ops getValidationApplicative 3 | */ 4 | export const getValidationApplicative = DSL.getValidationF( 5 | HKT.instance({ 6 | ...Either.Monad, 7 | ...Either.Run, 8 | ...Either.Fail, 9 | ...Either.Applicative 10 | }) 11 | ) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getWiltable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get a `Wiltable` instance for an `Either` given an 3 | * `AssociativeIdentity`. 4 | * 5 | * @tsplus static Either.Ops getWiltable 6 | */ 7 | export function getWiltable(M: AssociativeIdentity) { 8 | const separateF = Either.getSeparateF(M) 9 | return HKT.instance>>({ 10 | separateF 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/getWitherable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get a `Witherable` for an `Either` given an `AssociativeIdentity`. 3 | * 4 | * @tsplus static Either.Ops getWitherable 5 | */ 6 | export function getWitherable(M: AssociativeIdentity) { 7 | const compactF = Either.getCompactF(M) 8 | return HKT.instance>>({ 9 | compactF 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static Either.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => Either.right({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Applicative" 2 | 3 | /** 4 | * @tsplus static Either.Ops Applicative 5 | */ 6 | export const Applicative = HKT.instance>({ 7 | ...Either.Any, 8 | ...Either.Covariant, 9 | ...Either.AssociativeBoth 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static Either.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: Either.$.zip 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/AssociativeEither.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeEither" 2 | 3 | /** 4 | * @tsplus static Either.Ops AssociativeEither 5 | */ 6 | export const AssociativeEither = HKT.instance>({ 7 | orElseEither: (fb) => 8 | (fa) => fa._tag === "Right" ? Either.right(Either.left(fa.right)) : fb().map(Either.right) 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static Either.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (ffa) => ffa.flatten 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static Either.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: Either.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Fail.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FX/Fail" 2 | 3 | /** 4 | * @tsplus static Either.Ops Fail 5 | */ 6 | export const Fail = HKT.instance>({ 7 | fail: Either.left 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/FoldMap.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FoldMap" 2 | 3 | /** 4 | * @tsplus static Either.Ops FoldMap 5 | */ 6 | export const FoldMap = HKT.instance>({ 7 | foldMap: (I) => (f) => Either.$.foldMap(I, f) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Foldable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Foldable" 2 | 3 | /** 4 | * @tsplus static Either.Ops Foldable 5 | */ 6 | export const Foldable = HKT.instance>({ 7 | ...Either.FoldMap, 8 | ...Either.Reduce, 9 | ...Either.ReduceRight 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/ForEach.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEach" 2 | 3 | /** 4 | * @tsplus static Either.Ops ForEach 5 | */ 6 | export const ForEach = HKT.instance>({ 7 | ...Either.Covariant, 8 | forEachF: Either.forEachF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static Either.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...Either.Any, 8 | ...Either.Covariant, 9 | ...Either.AssociativeFlatten 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Reduce.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Reduce" 2 | 3 | /** 4 | * @tsplus static Either.Ops Reduce 5 | */ 6 | export const Reduce = HKT.instance>({ 7 | reduce: Either.$.reduce 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/ReduceRight.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ReduceRight" 2 | 3 | /** 4 | * @tsplus static Either.Ops ReduceRight 5 | */ 6 | export const ReduceRight = HKT.instance>({ 7 | reduceRight: Either.$.reduceRight 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/instances/Run.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FX/Run" 2 | 3 | /** 4 | * @tsplus static Either.Ops Run 5 | */ 6 | export const Run = HKT.instance>({ 7 | either: Either.right 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Use `A => B` to transform `Either` to `Either`. 3 | * 4 | * @tsplus static Either.Aspects map 5 | * @tsplus pipeable Either map 6 | */ 7 | export function map(f: (a: A) => B) { 8 | return (self: Either): Either => self.isLeft() ? self : Either.right(f(self.right)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/mapBoth.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Maps over both the `Left` and the `Right` values. 3 | * 4 | * @tsplus static Either.Aspects mapBoth 5 | * @tsplus pipeable Either mapBoth 6 | */ 7 | export function mapBoth(f: (e: E) => E1, g: (a: A) => B) { 8 | return (self: Either): Either => 9 | self.isLeft() ? Either.left(f(self.left)) : Either.right(g(self.right)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/mapLeft.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Use `E => E1` to transform `Either` to `Either` 3 | * 4 | * @tsplus static Either.Aspects mapLeft 5 | * @tsplus pipeable Either mapLeft 6 | */ 7 | export function mapLeft(f: (e: E) => E1) { 8 | return (self: Either): Either => self.isLeft() ? Either.left(f(self.left)) : self 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/merge.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Merges `Left | Right` into `A | B` 3 | * 4 | * @tsplus getter Either merge 5 | */ 6 | export function merge(self: Either): E | A { 7 | return self.fold( 8 | identity, 9 | identity 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/parseJSON.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a JavaScript Object Notation (JSON) string into an object. 3 | * 4 | * @tsplus static Either.Ops parseJSON 5 | */ 6 | export function parseJSON( 7 | s: string, 8 | onError: (reason: unknown) => E 9 | ): Either { 10 | return Either.tryCatch(() => JSON.parse(s), onError) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reduce a value `b` through an `Either`. 3 | * 4 | * @tsplus static Either.Aspects reduce 5 | * @tsplus pipeable Either reduce 6 | */ 7 | export function reduce(b: B, f: (b: B, a: A) => B) { 8 | return (self: Either): B => self.isLeft() ? b : f(b, self.right) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/reduceRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reduce a value `B` through an `Either` in inverted order. 3 | * 4 | * @tsplus static Either.Aspects reduceRight 5 | * @tsplus pipeable Either reduceRight 6 | */ 7 | export function reduceRight(b: B, f: (a: A, b: B) => B) { 8 | return (self: Either): B => self.isLeft() ? b : f(self.right, b) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/stringifyJSON.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. 3 | * 4 | * @tsplus static Either.Ops stringifyJSON 5 | */ 6 | export function stringifyJSON( 7 | u: unknown, 8 | onError: (reason: unknown) => E 9 | ): Either { 10 | return Either.tryCatch(() => JSON.stringify(u), onError) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/swap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Converst an `Either` into an `Either`. 3 | * 4 | * @tsplus getter Either swap 5 | */ 6 | export function swap(self: Either): Either { 7 | return self.isLeft() ? Either.right(self.left) : Either.left(self.right) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/tap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Similar to `flatMap`, but ignores the constructed output. 3 | * 4 | * @tsplus static Either.Aspects tap 5 | * @tsplus pipeable Either tap 6 | */ 7 | export function tap(f: (a: A) => Either) { 8 | return (self: Either): Either => self.flatMap((a) => f(a).map(() => a)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/tryCatch.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constructs a new `Either` from a function that might throw. 3 | * 4 | * @tsplus static Either.Ops tryCatch 5 | */ 6 | export function tryCatch( 7 | f: LazyArg, 8 | onError: (e: unknown) => E 9 | ): Either { 10 | try { 11 | return Either.right(f()) 12 | } catch (e) { 13 | return Either.left(onError(e)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/zipLeft.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply both and return the value of the first `Either`. 3 | * 4 | * @tsplus pipeable-operator Either < 5 | * @tsplus static Either.Aspects zipLeft 6 | * @tsplus pipeable Either zipLeft 7 | */ 8 | export function zipLeft(that: Either) { 9 | return (self: Either): Either => self.map((a) => () => a).ap(that) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Either/zipRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply both and return the value of the second `Either`. 3 | * 4 | * @tsplus pipeable-operator Either > 5 | * @tsplus static Either.Aspects zipRight 6 | * @tsplus pipeable Either zipRight 7 | */ 8 | export function zipRight(that: Either) { 9 | return (self: Either): Either => self.map(() => (b: B) => b).ap(that) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/LazyValue.ts: -------------------------------------------------------------------------------- 1 | export class LazyValue { 2 | static make = (f: () => A) => new LazyValue(f) 3 | 4 | constructor(private __lazy: () => A) {} 5 | get value(): A { 6 | const computed = this.__lazy() 7 | 8 | Object.defineProperty(this, "value", { 9 | value: computed 10 | }) 11 | 12 | return computed 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/ap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Classic applicative. 3 | * 4 | * @tsplus static Maybe.Aspects ap 5 | * @tsplus pipeable Maybe ap 6 | */ 7 | export function ap(that: Maybe) { 8 | return (self: Maybe<(a: A) => B>): Maybe => 9 | self.isNone() ? 10 | Maybe.none : 11 | that.isNone() ? 12 | Maybe.none : 13 | Maybe.some(self.value(that.value)) 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/apply.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constructs a new `Maybe` from a nullable type. If the value is `null` or 3 | * `undefined`, returns `None`, otherwise returns the value wrapped in a `Some`. 4 | * 5 | * @tsplus static Maybe.Ops __call 6 | */ 7 | export function apply(a: A): Maybe> { 8 | return Maybe.fromNullable(a) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/dsl/compactF.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops compactF 3 | */ 4 | export const compactF = Witherable.implementCompactF()((_) => 5 | (F) => (f) => (fa) => fa.isNone() ? DSL.succeedF(F)(Maybe.none) : f(fa.value) 6 | ) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/dsl/conditionals.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops if 3 | */ 4 | export const branch = DSL.conditionalF() 5 | 6 | /** 7 | * @tsplus static Maybe.Ops if_ 8 | */ 9 | export const branch_ = DSL.conditionalF_() 10 | 11 | export { branch as if, branch_ as if_ } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/dsl/gen.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops gen 3 | */ 4 | export const gen = DSL.genF(Maybe.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/dsl/struct.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops struct 3 | */ 4 | export const struct = DSL.structF({ 5 | ...Maybe.Monad, 6 | ...Maybe.Applicative 7 | }) 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/dsl/tuple.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops tuple 3 | */ 4 | export const tuple = DSL.tupleF({ 5 | ...Maybe.Monad, 6 | ...Maybe.Applicative 7 | }) 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/duplicate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Wraps this maybe into a second one. 3 | * 4 | * @tsplus getter Maybe duplicate 5 | * @tsplus static Maybe.Aspects duplicate 6 | */ 7 | export function duplicate(self: Maybe): Maybe> { 8 | return self.isNone() ? Maybe.none : Maybe.some(self) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/exists.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns `true` if the predicate is satisfied by the wrapped value. 3 | * 4 | * @tsplus static Maybe.Aspects exists 5 | * @tsplus pipeable Maybe exists 6 | */ 7 | export function exists(predicate: Predicate) { 8 | return (self: Maybe): boolean => self.isNone() ? false : predicate(self.value) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply `Maybe => B` in case self is some returning `Maybe`. 3 | * 4 | * @tsplus static Maybe.Aspects extend 5 | * @tsplus pipeable Maybe extend 6 | */ 7 | export function extend(f: (fa: Maybe) => B) { 8 | return (self: Maybe): Maybe => self.isNone() ? Maybe.none : Maybe.some(f(self)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/filterMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Aspects filterMap 3 | * @tsplus pipeable Maybe filterMap 4 | */ 5 | export function filterMap(f: (a: A) => Maybe) { 6 | return (self: Maybe): Maybe => self.isNone() ? Maybe.none : f(self.value) 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/flatMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Builds a new maybe constructed using the value of self. 3 | * 4 | * @tsplus static Maybe.Aspects flatMap 5 | * @tsplus pipeable Maybe flatMap 6 | */ 7 | export function flatMap(f: (a: A) => Maybe) { 8 | return (self: Maybe): Maybe => self.isNone() ? Maybe.none : f(self.value) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flattens nested options. 3 | * 4 | * @tsplus getter Maybe flatten 5 | * @tsplus static Maybe.Aspects flatten 6 | */ 7 | export function flatten(fa: Maybe>): Maybe { 8 | return fa.flatMap(identity) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/fromNullable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constructs a new `Maybe` from a nullable type. If the value is `null` or 3 | * `undefined`, returns `None`, otherwise returns the value wrapped in a `Some`. 4 | * 5 | * @tsplus static Maybe.Ops fromNullable 6 | */ 7 | export function fromNullable(a: A): Maybe> { 8 | return a == null ? Maybe.none : Maybe.some(a as NonNullable) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/getEquivalence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops getEquivalence 3 | */ 4 | export function getEquivalence(E: Equivalence): Equivalence> { 5 | return Equivalence((x, y) => 6 | x === y || x.isNone() ? y.isNone() : y.isNone() ? false : E.equals(x.value, y.value) 7 | ) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/getOrd.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops getOrd 3 | */ 4 | export function getOrd(O: Ord): Ord> { 5 | return Ord((x, y) => x === y ? 0 : x.isSome() ? y.isSome() ? O.compare(x.value, y.value) : 1 : -1) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/getShow.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops getShow 3 | */ 4 | export function getShow(S: Show): Show> { 5 | return Show((maybe) => maybe.isNone() ? "None" : `Some(${S.show(maybe.value)})`) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => Maybe.some({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Applicative" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Applicative 5 | */ 6 | export const Applicative = HKT.instance>({ 7 | ...Maybe.Covariant, 8 | ...Maybe.IdentityBoth 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: Maybe.$.zip 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (maybe) => maybe.flatten 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Compactable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Compactable" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Compactable 5 | */ 6 | export const Compactable = HKT.instance>({ 7 | compact: (maybe) => maybe.flatten, 8 | separate: (maybe) => maybe.separate 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: Maybe.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Extend.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Extend" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Extend 5 | */ 6 | export const Extend = HKT.instance>({ 7 | extend: Maybe.$.extend 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Fail.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/FX/Fail" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Fail 5 | */ 6 | export const Fail = HKT.instance>({ 7 | fail: () => Maybe.none 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Filterable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Filterable" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Filterable 5 | */ 6 | export const Filterable = HKT.instance>({ 7 | filter: Maybe.$.filter, 8 | filterMap: Maybe.$.filterMap, 9 | partition: Maybe.$.partition, 10 | partitionMap: Maybe.$.partitionMap 11 | }) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/ForEach.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/ForEach" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops ForEach 5 | */ 6 | export const ForEach = HKT.instance>({ 7 | ...Maybe.Covariant, 8 | forEachF: Maybe.forEachF 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/IdentityBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/IdentityBoth" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops IdentityBoth 5 | */ 6 | export const IdentityBoth = HKT.instance>({ 7 | ...Maybe.Any, 8 | ...Maybe.AssociativeBoth 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/IdentityFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/IdentityFlatten" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops IdentityFlatten 5 | */ 6 | export const OptionIdentityFlatten = HKT.instance>({ 7 | ...Maybe.Any, 8 | ...Maybe.AssociativeFlatten 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...Maybe.Covariant, 8 | ...Maybe.IdentityFlatten 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Wiltable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Wiltable" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Wiltable 5 | */ 6 | export const Wiltable = HKT.instance>({ 7 | separateF: Maybe.separateF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/instances/Witherable.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Witherable" 2 | 3 | /** 4 | * @tsplus static Maybe.Ops Witherable 5 | */ 6 | export const Witherable = HKT.instance>({ 7 | compactF: Maybe.compactF 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/map.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Use `A => B` to transform `Maybe` to `Maybe`. 3 | * 4 | * @tsplus static Maybe.Aspects map 5 | * @tsplus pipeable Maybe map 6 | */ 7 | export function map(f: (a: A) => B) { 8 | return (self: Maybe): Maybe => self.isNone() ? Maybe.none : Maybe.some(f(self.value)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/mapNullable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This is `chain` + `fromNullable`, useful when working with optional values. 3 | * 4 | * @tsplus static Maybe.Aspects mapNullable 5 | * @tsplus pipeable Maybe mapNullable 6 | */ 7 | export function mapNullable(f: (a: A) => B | null | undefined) { 8 | return (self: Maybe): Maybe => 9 | self.isNone() ? Maybe.none : Maybe.fromNullable(f(self.value)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/orElse.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus pipeable-operator Maybe | 3 | * @tsplus static Maybe.Aspects orElse 4 | * @tsplus pipeable Maybe orElse 5 | */ 6 | export function orElse(onNone: LazyArg>) { 7 | return (self: Maybe): Maybe => self.isNone() ? onNone() : self 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/partitionMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Aspects partitionMap 3 | * @tsplus pipeable Maybe partitionMap 4 | */ 5 | export function partitionMap(f: (a: A) => Either) { 6 | return (self: Maybe): readonly [Maybe, Maybe] => self.map(f).separate 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/separate.ts: -------------------------------------------------------------------------------- 1 | const defaultSeparate = [Maybe.none, Maybe.none] as const 2 | 3 | /** 4 | * @tsplus getter Maybe separate 5 | */ 6 | export function separate( 7 | self: Maybe> 8 | ): readonly [Maybe, Maybe] { 9 | const maybe = self.map((either) => [either.left, either.right] as const) 10 | return maybe.isNone() ? defaultSeparate : maybe.value 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/sequence.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Maybe.Ops sequence 3 | */ 4 | export const sequence = ForEach.sequenceF(Maybe.ForEach) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/tap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Like chain but ignores the constructed outout. 3 | * 4 | * @tsplus static Maybe.Aspects tap 5 | * @tsplus pipeable Maybe tap 6 | */ 7 | export function tap(f: (a: A) => Maybe) { 8 | return (self: Maybe): Maybe => self.flatMap((a) => f(a).map(() => a)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/toNullable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Extracts the value out of the structure, if it exists. Otherwise returns 3 | * `null`. 4 | * 5 | * @tsplus getter Maybe toNullable 6 | */ 7 | export function toNullable(self: Maybe): A | null { 8 | return self.isNone() ? null : self.value 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/toUndefined.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Extracts the value out of the structure, if it exists. Otherwise returns 3 | * `undefined`. 4 | * 5 | * @tsplus getter Maybe value 6 | */ 7 | export function toUndefined(self: Maybe): A | undefined { 8 | return self.isNone() ? undefined : self.value 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/tryCatch.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Transforms an exception into an `Maybe`. If `f` throws, returns `None`, 3 | * otherwise returns the output wrapped in `Some`. 4 | * 5 | * @tsplus static Maybe.Ops tryCatch 6 | */ 7 | export function tryCatch(f: LazyArg): Maybe { 8 | try { 9 | return Maybe.some(f()) 10 | } catch (e) { 11 | return Maybe.none 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/zip.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Zips `Maybe` and `Maybe` into `Maybe>`. 3 | * 4 | * @tsplus pipeable-operator Maybe + 5 | * @tsplus static Maybe.Aspects zip 6 | * @tsplus pipeable Maybe zip 7 | */ 8 | export function zip(that: Maybe) { 9 | return (self: Maybe): Maybe => self.flatMap((a) => that.map((b) => [a, b])) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/zipLeft.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply both and return first. 3 | * 4 | * @tsplus pipeable-operator Maybe < 5 | * @tsplus static Maybe.Aspects zipLeft 6 | * @tsplus pipeable Maybe zipLeft 7 | */ 8 | export function zipLeft(that: Maybe) { 9 | return (self: Maybe): Maybe => self.flatMap((a) => that.map(() => a)) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/zipRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Apply both and return second. 3 | * 4 | * @tsplus pipeable-operator Maybe > 5 | * @tsplus static Maybe.Aspects zipRight 6 | * @tsplus pipeable Maybe zipRight 7 | */ 8 | export function zipRight(that: Maybe) { 9 | return (self: Maybe): Maybe => self.flatMap(() => that) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Maybe/zipWith.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Zips `Maybe` and `Maybe` into `Maybe` using the provided zipper. 3 | * 4 | * @tsplus static Maybe.Aspects zipWith 5 | * @tsplus pipeable Maybe zipWith 6 | */ 7 | export function zipWith(that: Maybe, f: (a: A, b: B) => C) { 8 | return (self: Maybe): Maybe => self.flatMap((a) => that.map((b) => f(a, b))) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Predicate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Predicate 3 | */ 4 | export interface Predicate { 5 | (a: A): boolean 6 | } 7 | 8 | /** 9 | * Inverts a boolean predicate 10 | */ 11 | export function not(predicate: Predicate): Predicate { 12 | return (a) => !predicate(a) 13 | } 14 | -------------------------------------------------------------------------------- /packages/stdlib/_src/data/Stack.ts: -------------------------------------------------------------------------------- 1 | export class Stack { 2 | constructor(readonly value: A, readonly previous?: Stack) {} 3 | } 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/exceptions.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./exceptions/*.ts, prefix: "@tsplus/stdlib"} 2 | export * from "@tsplus/stdlib/exceptions/Exception" 3 | export * from "@tsplus/stdlib/exceptions/IndexOutOfBounds" 4 | export * from "@tsplus/stdlib/exceptions/NoSuchElement" 5 | export * from "@tsplus/stdlib/exceptions/PrematureGeneratorExit" 6 | // codegen:end 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/exceptions/Exception.ts: -------------------------------------------------------------------------------- 1 | export abstract class Exception { 2 | abstract readonly message: string 3 | } 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/exceptions/IndexOutOfBounds.ts: -------------------------------------------------------------------------------- 1 | export const IndexOutOfBoundsTag = "IndexOutOfBounds" 2 | 3 | export class IndexOutOfBounds extends Exception { 4 | readonly _tag = IndexOutOfBoundsTag 5 | readonly message: string = `${this.index} is out of bounds (min ${this.min}, max ${this.max})` 6 | constructor(readonly index: number, readonly min: number, readonly max: number) { 7 | super() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/exceptions/NoSuchElement.ts: -------------------------------------------------------------------------------- 1 | export const NoSuchElementTag = "NoSuchElement" 2 | 3 | export class NoSuchElement { 4 | readonly _tag = NoSuchElementTag 5 | } 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io.ts: -------------------------------------------------------------------------------- 1 | export * as eval from "@tsplus/stdlib/io/Eval" 2 | export * as random from "@tsplus/stdlib/io/Random" 3 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Takes a function `Eval => B` and return an `Eval` 3 | * 4 | * @tsplus static Eval.Aspects extend 5 | * @tsplus pipeable Eval extend 6 | */ 7 | export function extend(f: (fa: Eval) => B) { 8 | return (self: Eval): Eval => Eval.succeedNow(f(self)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/flatten.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flatten an `Eval>` into an `Eval` 3 | * 4 | * @tsplus getter Eval flatten 5 | */ 6 | export function flatten(self: Eval>): Eval { 7 | return self.flatMap(identity) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Any.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Any" 2 | 3 | /** 4 | * @tsplus static Eval.Ops Any 5 | */ 6 | export const Any = HKT.instance>({ 7 | any: () => Eval.succeedNow({}) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Applicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Eval.Ops Applicative 3 | */ 4 | export const Applicative = DSL.getApplicativeF(Eval.Monad) 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Apply.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Apply" 2 | 3 | /** 4 | * @tsplus static Eval.Ops Apply 5 | */ 6 | export const Apply = HKT.instance>({ 7 | ...Eval.AssociativeBoth, 8 | ...Eval.Covariant 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/AssociativeBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeBoth" 2 | 3 | /** 4 | * @tsplus static Eval.Ops AssociativeBoth 5 | */ 6 | export const AssociativeBoth = HKT.instance>({ 7 | both: (that) => Eval.$.zip(that) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/AssociativeFlatten.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/AssociativeFlatten" 2 | 3 | /** 4 | * @tsplus static Eval.Ops AssociativeFlatten 5 | */ 6 | export const AssociativeFlatten = HKT.instance>({ 7 | flatten: (ffa) => ffa.flatMap(identity) 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Covariant.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Covariant" 2 | 3 | /** 4 | * @tsplus static Eval.Ops Covariant 5 | */ 6 | export const Covariant = HKT.instance>({ 7 | map: Eval.$.map 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Extend.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Extend" 2 | 3 | /** 4 | * @tsplus static Eval.Ops Extend 5 | */ 6 | export const Extend = HKT.instance>({ 7 | extend: Eval.$.extend 8 | }) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/IdentityBoth.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/IdentityBoth" 2 | 3 | /** 4 | * @tsplus static Eval.Ops IdentityBoth 5 | */ 6 | export const IdentityBoth = HKT.instance>({ 7 | ...Eval.AssociativeBoth, 8 | ...Eval.Any 9 | }) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/instances/Monad.ts: -------------------------------------------------------------------------------- 1 | import type * as P from "@tsplus/stdlib/prelude/Monad" 2 | 3 | /** 4 | * @tsplus static Eval.Ops Monad 5 | */ 6 | export const Monad = HKT.instance>({ 7 | ...Eval.Any, 8 | ...Eval.AssociativeFlatten, 9 | ...Eval.Covariant 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Eval.Ops reduce 3 | */ 4 | export function reduce( 5 | as: Collection, 6 | b: LazyArg, 7 | f: (b: B, a: A) => Eval 8 | ): Eval { 9 | return as.reduce(Eval.succeed(b), (b, a) => b.flatMap((b) => f(b, a))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/succeed.ts: -------------------------------------------------------------------------------- 1 | import { Succeed } from "@tsplus/stdlib/io/Eval/definition" 2 | 3 | /** 4 | * Lift a sync (non failable) computation. 5 | * 6 | * @tsplus static Eval.Ops __call 7 | * @tsplus static Eval.Ops succeed 8 | */ 9 | export function succeed(a: LazyArg): Eval { 10 | return new Succeed(a) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/succeedNow.ts: -------------------------------------------------------------------------------- 1 | import { Succeed } from "@tsplus/stdlib/io/Eval/definition" 2 | 3 | /** 4 | * Constructs a computation that always succeeds with the specified value. 5 | * 6 | * @tsplus static Eval.Ops succeedNow 7 | */ 8 | export function succeedNow(a: A): Eval { 9 | return new Succeed(() => a) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/suspend.ts: -------------------------------------------------------------------------------- 1 | import type { EvalInternal } from "@tsplus/stdlib/io/Eval" 2 | import { Suspend } from "@tsplus/stdlib/io/Eval/definition" 3 | 4 | /** 5 | * Suspend a computation, useful in recursion. 6 | * 7 | * @tsplus static Eval.Ops suspend 8 | */ 9 | export function suspend(f: LazyArg>): Eval { 10 | return new Suspend(f as LazyArg>) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/tap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns a computation that effectfully "peeks" at the success of this one. 3 | * 4 | * @tsplus static Eval.Aspects tap 5 | * @tsplus pipeable Eval tap 6 | */ 7 | export function tap(f: (a: A) => Eval) { 8 | return (self: Eval): Eval => self.flatMap((a) => f(a).map(() => a)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/unit.ts: -------------------------------------------------------------------------------- 1 | import { Succeed } from "@tsplus/stdlib/io/Eval/definition" 2 | 3 | /** 4 | * Constructs a computation that always returns the `Unit` value. 5 | * 6 | * @tsplus static Eval.Ops unit 7 | */ 8 | export const unit: Eval = new Succeed(() => undefined) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/zip.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Combines this computation with the specified computation combining the 3 | * results of both into a tuple. 4 | * 5 | * @tsplus static Eval.Aspects zip 6 | * @tsplus pipeable Eval zip 7 | */ 8 | export function zip(that: Eval) { 9 | return (self: Eval): Eval => self.zipWith(that, (a, b) => [a, b]) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/zipLeft.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Combines this computation with the specified computation, returning the 3 | * value of this computation. 4 | * 5 | * @tsplus pipeable-operator Eval < 6 | * @tsplus static Eval.Aspects zipLeft 7 | * @tsplus pipeable Eval zipLeft 8 | */ 9 | export function zipLeft(that: Eval) { 10 | return (self: Eval): Eval => self.zipWith(that, (a, _) => a) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/zipRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Combines this computation with the specified computation, returning the 3 | * value of that computation. 4 | * 5 | * @tsplus pipeable-operator Eval > 6 | * @tsplus static Eval.Aspects zipRight 7 | * @tsplus pipeable Eval zipRight 8 | */ 9 | export function zipRight(that: Eval) { 10 | return (self: Eval): Eval => self.zipWith(that, (_, b) => b) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Eval/zipWith.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Combines this computation with the specified computation combining the 3 | * results of both using the specified function. 4 | * 5 | * @tsplus static Eval.Aspects zipWith 6 | * @tsplus pipeable Eval zipWith 7 | */ 8 | export function zipWith(that: Eval, f: (a: A, b: B) => C) { 9 | return (self: Eval): Eval => self.flatMap((a) => that.map((b) => f(a, b))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Random.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Random/*.ts, prefix: "@tsplus/stdlib/io"} 2 | export * from "@tsplus/stdlib/io/Random/Distribution" 3 | export * from "@tsplus/stdlib/io/Random/Generator" 4 | export * from "@tsplus/stdlib/io/Random/MutableRandom" 5 | export * from "@tsplus/stdlib/io/Random/PCGRandom" 6 | // codegen:end 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Random/Distribution.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Distribution/*.ts, prefix: "@tsplus/stdlib/io/Random"} 2 | export * from "@tsplus/stdlib/io/Random/Distribution/definition" 3 | export * from "@tsplus/stdlib/io/Random/Distribution/operations" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/io/Random/Generator.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Generator/*.ts, prefix: "@tsplus/stdlib/io/Random"} 2 | export * from "@tsplus/stdlib/io/Random/Generator/MersenneTwister" 3 | export * from "@tsplus/stdlib/io/Random/Generator/RandomGenerator" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Any.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Any 3 | */ 4 | export interface Any extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Any: "Any" 7 | } 8 | readonly any: () => HKT.Kind 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Applicative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Applicative 3 | */ 4 | export type Applicative = IdentityBoth & Covariant 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Apply.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Apply 3 | */ 4 | export type Apply = AssociativeBoth & Covariant 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/all.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Boolean `Associative` under conjunction. 3 | * 4 | * @tsplus static Associative/Ops all 5 | */ 6 | export const all: Associative = Associative((x, y) => x && y) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/any.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Boolean `Associative` under disjunction. 3 | * 4 | * @tsplus static Associative/Ops any 5 | */ 6 | export const any: Associative = Associative((x, y) => x || y) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/first.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An `Associative` that always returns the first element. 3 | * 4 | * @tsplus static Associative/Ops first 5 | */ 6 | export function first(): Associative { 7 | return Associative((x, _) => x) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/fold.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Fold `Associative` through a `Collection`. 3 | * 4 | * @tsplus static Associative/Ops fold 5 | */ 6 | export function fold(S: Associative) { 7 | return (init: A) => 8 | (collection: Collection): A => collection.reduce(init, (x, y) => S.combine(x, y)) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/function.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Associative` for function combination. 3 | * 4 | * @tsplus static Associative/Ops function 5 | */ 6 | export function function_(S: Associative): () => Associative<(a: A) => S> { 7 | return () => Associative((f, g) => (a) => S.combine(f(a), g(a))) 8 | } 9 | 10 | export { function_ as function } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/intercalate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Intercalate the specified value between elements when combining. 3 | * 4 | * @tsplus fluent Associative intercalate 5 | */ 6 | export function intercalate(self: Associative, value: A): Associative { 7 | return Associative((x, y) => self.combine(x, self.combine(value, y))) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/inverted.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The dual of a `Associative`, obtained by swapping the arguments of `combine`. 3 | * 4 | * @tsplus getter Associative inverted 5 | */ 6 | export function inverted(self: Associative): Associative { 7 | return Associative((x, y) => self.combine(y, x)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/last.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An `Associative` that always returns the last element. 3 | * 4 | * @tsplus static Associative/Ops last 5 | */ 6 | export function last(): Associative { 7 | return Associative((_, y) => y) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/max.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Associative` that returns the last max of elements. 3 | * 4 | * @tsplus static Associative/Ops max 5 | */ 6 | export function max(O: Ord): Associative { 7 | return Associative(O.max) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/min.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Associative` that returns last min of elements. 3 | * 4 | * @tsplus static Associative/Ops min 5 | */ 6 | export function min(O: Ord): Associative { 7 | return Associative(O.min) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/object.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns a `Associative` instance for objects preserving their type. 3 | * 4 | * @tsplus static Associative/Ops object 5 | */ 6 | export function object(): Associative { 7 | return Associative((x, y) => Object.assign({}, x, y)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/product.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Number `Associative` under multiplication. 3 | * 4 | * @tsplus static Associative/Ops product 5 | */ 6 | export const product: Associative = Associative((x, y) => x * y) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/string.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * String `Associative` under concatenation. 3 | * 4 | * @tsplus static Associative/Ops string 5 | */ 6 | export const string: Associative = Associative((x, y) => x + y) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/sum.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Number `Associative` under addition. 3 | * 4 | * @tsplus static Associative/Ops sum 5 | */ 6 | export const sum: Associative = Associative((x, y) => x + y) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Associative/void.ts: -------------------------------------------------------------------------------- 1 | import { constVoid } from "@tsplus/stdlib/data/Function" 2 | 3 | /** 4 | * Void `Associative`. 5 | * 6 | * @tsplus static Associative/Ops void 7 | */ 8 | export const void_: Associative = Associative(constVoid) 9 | 10 | export { void_ as void } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeCompose.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type AssociativeCompose 3 | */ 4 | export interface AssociativeCompose extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly AssociativeCompose: "AssociativeCompose" 7 | } 8 | readonly compose: ( 9 | bc: HKT.Kind 10 | ) => (ab: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/all.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Boolean `AssociativeIdentity` under conjunction. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops all 5 | */ 6 | export const all: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | true, 8 | Associative.all 9 | ) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/any.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Boolean `AssociativeIdentity` under disjunction. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops any 5 | */ 6 | export const any: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | false, 8 | Associative.any 9 | ) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/endomorphism.ts: -------------------------------------------------------------------------------- 1 | import type { Endomorphism } from "@tsplus/stdlib/data/Function" 2 | 3 | /** 4 | * `AssociativeIdentity` for an `Endomorphism`. 5 | * 6 | * @tsplus static AssociativeIdentity/Ops endomorphism 7 | */ 8 | export function endomorphism(): AssociativeIdentity> { 9 | return AssociativeIdentity((a) => a, (x, y) => (a) => x(y(a))) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/fold.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Folds an `AssociativeIdentity` through a `Collection`. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops fold 5 | */ 6 | export function fold(M: AssociativeIdentity) { 7 | return (collection: Collection): A => Associative.fold(M)(M.identity)(collection) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/fromAssociative.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Derive an `AssociativeIdentity` from `Associative` and `identity`. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops fromAssociative 5 | */ 6 | export function fromAssociative( 7 | identity: A, 8 | associative: Associative 9 | ): AssociativeIdentity { 10 | return AssociativeIdentity(identity, associative.combine) 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/inverted.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The dual of a `AssociativeIdentity`, obtained by swapping the arguments of `concat`. 3 | * 4 | * @tsplus getter AssociativeIdentity inverted 5 | */ 6 | export function inverted(I: AssociativeIdentity): AssociativeIdentity { 7 | return AssociativeIdentity(I.identity, (x, y) => I.combine(y, x)) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/max.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `AssociativeIdentity` that returns last max of elements. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops max 5 | */ 6 | export function max(B: Bounded): AssociativeIdentity { 7 | return AssociativeIdentity(B.bottom, Associative.max(B).combine) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/min.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `AssociativeIdentity` that returns last min of elements. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops min 5 | */ 6 | export function min(B: Bounded): AssociativeIdentity { 7 | return AssociativeIdentity(B.top, Associative.min(B).combine) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/product.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Number `AssociativeIdentity` under multiplication. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops product 5 | */ 6 | export const product: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | 1, 8 | Associative.product 9 | ) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/string.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * String `AssociativeIdentity` under concatenation. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops string 5 | */ 6 | export const string: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | "", 8 | Associative.string 9 | ) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/sum.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Number `AssociativeIdentity` under addition. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops sum 5 | */ 6 | export const sum: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | 0, 8 | Associative.sum 9 | ) 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/AssociativeIdentity/void.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Void `AssociativeIdentity`. 3 | * 4 | * @tsplus static AssociativeIdentity/Ops void 5 | */ 6 | export const void_: AssociativeIdentity = AssociativeIdentity.fromAssociative( 7 | undefined, 8 | Associative.void 9 | ) 10 | 11 | export { void_ as void } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Bounded.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Bounded 3 | */ 4 | export interface Bounded extends Ord { 5 | readonly top: A 6 | readonly bottom: A 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Category.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Category 3 | */ 4 | export type Category = { 5 | readonly Law: { 6 | readonly Category: "Category" 7 | } 8 | readonly id: () => HKT.Kind 9 | } & AssociativeCompose 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Closure.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Closure/*.ts, prefix: "@tsplus/stdlib/prelude"} 2 | export * from "@tsplus/stdlib/prelude/Closure/definition" 3 | // codegen:end 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/CommutativeBoth.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An commutative binary operator that combines two values of types `F` 3 | * and `F` to produce an `F>`. 4 | * 5 | * @tsplus type CommutativeBoth 6 | */ 7 | export type CommutativeBoth = { 8 | readonly Law: { 9 | readonly CommutativeBoth: "CommutativeBoth" 10 | } 11 | } & AssociativeBoth 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/CommutativeEither.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A commutative binary operator that combines two values of types `F` and 3 | * `F` to produce an `F>`. 4 | * 5 | * @tsplus type CommutativeEither 6 | */ 7 | export type CommutativeEither = { 8 | readonly Law: { 9 | readonly CommutativeEither: "CommutativeEither" 10 | } 11 | } & AssociativeEither 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Compact.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Compact 3 | */ 4 | export interface Compact extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Compact: "Compact" 7 | } 8 | readonly compact: (fa: HKT.Kind>) => HKT.Kind 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Compactable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Compactable 3 | */ 4 | export type Compactable = Compact & Separate 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/CovariantWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type CovariantWithIndex 3 | */ 4 | export interface CovariantWithIndex extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly CovariantWithIndex: "CovariantWithIndex" 7 | } 8 | readonly mapWithIndex: ( 9 | f: (k: K, a: A) => B 10 | ) => (fa: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/DSL/_internal/curried.ts: -------------------------------------------------------------------------------- 1 | export function curried(f: Function, n: number, acc: ReadonlyArray) { 2 | return function(x: unknown) { 3 | const combined = acc.concat([x]) 4 | // eslint-disable-next-line prefer-spread 5 | return n === 0 ? f.apply(null, combined) : curried(f, n - 1, combined) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/DSL/definition.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type DSL 3 | */ 4 | export interface DSLOps {} 5 | export const DSL: DSLOps = {} 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/DSL/getApplicativeF.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static DSL getApplicativeF 3 | */ 4 | export function getApplicativeF(F: Monad): Applicative { 5 | const Apply = DSL.getApplyF(F) 6 | return HKT.instance({ 7 | ...Apply, 8 | any: F.any 9 | }) 10 | } 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/DSL/succeedF.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static DSL succeedF 3 | */ 4 | export function succeedF(F: Covariant & Any) { 5 | return (a: A): HKT.Kind => F.map(() => a)(F.any()) 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Derive.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Derive 3 | */ 4 | export interface Derive extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Derive: "Derive" 7 | } 8 | readonly derive: (fa: HKT.Kind) => HKT.Kind> 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/any.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Equality for `unknown` values. Note that since values of type `unknown` contain 3 | * no information, all values of type `unknown` can be treated as equal to each 4 | * other. 5 | * 6 | * @tsplus static Equivalence/Ops any 7 | */ 8 | export const any: Equivalence = Equivalence(() => true) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/boolean.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Equivalence` for `boolean` values. 3 | * 4 | * @tsplus static Equivalence/Ops boolean 5 | */ 6 | export const boolean = Equivalence.strict() 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/date.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Equivalence` for `Date` values. 3 | * 4 | * @tsplus static Equivalence/Ops date 5 | */ 6 | export const date: Equivalence = Equivalence.number.contramap((date: Date) => date.valueOf()) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/never.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Equality for `never` values. Note that since there are not values of 3 | * type `never` the `equals` method of this instance can never be called 4 | * but it can be useful in deriving instances for more complex types. 5 | * 6 | * @tsplus static Equivalence/Ops never 7 | */ 8 | export const never: Equivalence = Equivalence(() => false) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/number.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Equivalence` for `number` values. 3 | * 4 | * @tsplus static Equivalence/Ops number 5 | */ 6 | export const number = Equivalence.strict() 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/strict.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Constructs an `Equivalence` that uses the default notion of equality 3 | * embodied in the implementation of `equals` for values of type `A`. 4 | * 5 | * @tsplus static Equivalence/Ops strict 6 | */ 7 | export function strict() { 8 | return Equivalence((x, y) => x === y) 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/string.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Equivalence` for `string` values. 3 | * 4 | * @tsplus static Equivalence/Ops string 5 | */ 6 | export const string = Equivalence.strict() 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Equivalence/symbol.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * `Equivalence` for `symbol` values. 3 | * 4 | * @tsplus static Equivalence/Ops symbol 5 | */ 6 | export const symbol = Equivalence.strict() 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Extend.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Extend 3 | */ 4 | export interface Extend extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Extend: "Extend" 7 | } 8 | readonly extend: ( 9 | f: (fa: HKT.Kind) => B 10 | ) => (fa: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FX.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ts-plus/stdlib/d0a7c775279d647b48fe6edd123860398a296cd2/packages/stdlib/_src/prelude/FX.ts -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FX/Access.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Access 3 | */ 4 | export interface Access extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Access: "Access" 7 | } 8 | readonly access: (f: (_: R) => A) => HKT.Kind 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FX/Fail.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Fail 3 | */ 4 | export interface Fail extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Fail: "Fail" 7 | } 8 | readonly fail: (e: E) => HKT.Kind 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FX/Provide.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Provide 3 | */ 4 | export interface Provide extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Provide: "Provide" 7 | } 8 | readonly provide: ( 9 | r: R 10 | ) => (fa: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FX/Run.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Run 3 | */ 4 | export interface Run extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Run: "Run" 7 | } 8 | readonly either: (fa: HKT.Kind) => HKT.Kind> 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FilterMap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type FilterMap 3 | */ 4 | export interface FilterMap extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly FilterMap: "FilterMap" 7 | } 8 | readonly filterMap: ( 9 | f: (a: A) => Maybe 10 | ) => (fa: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FilterMapWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type FilterMapWithIndex 3 | */ 4 | export interface FilterMapWithIndex extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly FilterMapWithIndex: "FilterMapWithIndex" 7 | } 8 | readonly filterMapWithIndex: ( 9 | f: (k: K, a: A) => Maybe 10 | ) => (fa: HKT.Kind) => HKT.Kind 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Filterable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Filterable 3 | */ 4 | export type Filterable = 5 | & Filter 6 | & FilterMap 7 | & Partition 8 | & PartitionMap 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FilterableWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type FilterableWithIndex 3 | */ 4 | export type FilterableWithIndex = 5 | & FilterWithIndex 6 | & PartitionWithIndex 7 | & FilterMapWithIndex 8 | & PartitionMapWithIndex 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Foldable.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Foldable 3 | */ 4 | export type Foldable = ReduceRight & Reduce & FoldMap 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/FoldableWithIndex.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type FoldableWithIndex 3 | */ 4 | export type FoldableWithIndex = 5 | & ReduceRightWithIndex 6 | & ReduceWithIndex 7 | & FoldMapWithIndex 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Identity.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Identity/*.ts, prefix: "@tsplus/stdlib/prelude"} 2 | export * from "@tsplus/stdlib/prelude/Identity/definition" 3 | // codegen:end 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/IdentityBoth.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A binary operator that combines two values of types `F` and `F` to 3 | * produce an `F>` with an identity. 4 | */ 5 | export type IdentityBoth = AssociativeBoth & Any 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/IdentityEither.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * A binary operator that combines two values of types `F` and `F` to 3 | * produce an `F>` with an identity value. 4 | * 5 | * @tsplus type IdentityEither 6 | */ 7 | export type IdentityEither = AssociativeEither & None 8 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Monad.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Monad 3 | */ 4 | export type Monad = IdentityFlatten & Covariant 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/None.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type None 3 | */ 4 | export interface None extends HKT.Typeclass { 5 | readonly never: () => HKT.Kind 6 | } 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ord/consecutive.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Order by first, second, third, etc. 3 | * 4 | * @tsplus static Ord/Ops consecutive 5 | */ 6 | export function consecutive(...ords: Array>): Ord { 7 | return AssociativeIdentity.fold(Ord.getAssociativeIdentity())(ords) 8 | } 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ordering.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./Ordering/*.ts, prefix: "@tsplus/stdlib/prelude"} 2 | export * from "@tsplus/stdlib/prelude/Ordering/definition" 3 | export * from "@tsplus/stdlib/prelude/Ordering/instances" 4 | export * from "@tsplus/stdlib/prelude/Ordering/operations" 5 | // codegen:end 6 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ordering/definition.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Ordering 3 | */ 4 | export type Ordering = -1 | 0 | 1 5 | 6 | /** 7 | * @tsplus type Ordering/Ops 8 | */ 9 | export interface OrderingOps {} 10 | export const Ordering: OrderingOps = {} 11 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ordering/instances.ts: -------------------------------------------------------------------------------- 1 | // codegen:start {preset: barrel, include: ./instances/*.ts, prefix: "@tsplus/stdlib/prelude/Ordering"} 2 | export * from "@tsplus/stdlib/prelude/Ordering/instances/Associative" 3 | export * from "@tsplus/stdlib/prelude/Ordering/instances/AssociativeIdentity" 4 | // codegen:end 5 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ordering/instances/Associative.ts: -------------------------------------------------------------------------------- 1 | import * as A from "@tsplus/stdlib/prelude/Associative/definition" 2 | 3 | /** 4 | * `Associative` instance for `Ordering`. 5 | * 6 | * @tsplus static Ordering/Ops Associative 7 | */ 8 | export const Associative = A.Associative((x, y) => x !== 0 ? x : y) 9 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Ordering/instances/AssociativeIdentity.ts: -------------------------------------------------------------------------------- 1 | import * as A from "@tsplus/stdlib/prelude/AssociativeIdentity/definition" 2 | 3 | /** 4 | * `AssociativeIdentity` instance for `Ordering`. 5 | * 6 | * @tsplus static Ordering/Ops AssociativeIdentity 7 | */ 8 | export const AssociativeIdentity = A.AssociativeIdentity.fromAssociative( 9 | 0, 10 | Ordering.Associative 11 | ) 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Reduce.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Reduce 3 | */ 4 | export interface Reduce extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Reduce: "Reduce" 7 | } 8 | readonly reduce: (b: B, f: (b: B, a: A) => B) => (fa: HKT.Kind) => B 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/ReduceRight.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type ReduceRight 3 | */ 4 | export interface ReduceRight extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly ReduceRight: "ReduceRight" 7 | } 8 | readonly reduceRight: (b: B, f: (a: A, b: B) => B) => (fa: HKT.Kind) => B 9 | } 10 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Separate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus type Separate 3 | */ 4 | export interface Separate extends HKT.Typeclass { 5 | readonly Law: { 6 | readonly Separate: "Separate" 7 | } 8 | readonly separate: ( 9 | fa: HKT.Kind> 10 | ) => readonly [HKT.Kind, HKT.Kind] 11 | } 12 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Show/boolean.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Show/Ops boolean 3 | */ 4 | export const boolean: Show = Show( 5 | (a) => JSON.stringify(a) 6 | ) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Show/number.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Show/Ops number 3 | */ 4 | export const number: Show = Show( 5 | (a) => JSON.stringify(a) 6 | ) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Show/string.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Show/Ops string 3 | */ 4 | export const string: Show = Show( 5 | (a) => JSON.stringify(a) 6 | ) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_src/prelude/Show/tuple.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @tsplus static Show/Ops tuple 3 | */ 4 | export function tuple>>( 5 | ...shows: T 6 | ): Show< 7 | { 8 | [K in keyof T]: T[K] extends Show ? A : never 9 | } 10 | > { 11 | return Show( 12 | (t) => `[${t.map((a, i) => shows[i]!.show(a)).join(", ")}]` 13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /packages/stdlib/_src/service.ts: -------------------------------------------------------------------------------- 1 | export * as env from "@tsplus/stdlib/service/Env" 2 | export * as service from "@tsplus/stdlib/service/Service" 3 | export * as tag from "@tsplus/stdlib/service/Tag" 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/structure.ts: -------------------------------------------------------------------------------- 1 | export * as copy from "@tsplus/stdlib/structure/Copy" 2 | export * as equals from "@tsplus/stdlib/structure/Equals" 3 | export * as hash from "@tsplus/stdlib/structure/Hash" 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/type-level.ts: -------------------------------------------------------------------------------- 1 | export { Check } from "@tsplus/stdlib/type-level/check" 2 | export { TypeLevel } from "@tsplus/stdlib/type-level/common" 3 | -------------------------------------------------------------------------------- /packages/stdlib/_src/utilities.ts: -------------------------------------------------------------------------------- 1 | export * as guard from "@tsplus/stdlib/utilities/Guards" 2 | export * as lazy from "@tsplus/stdlib/utilities/Lazy" 3 | export * as types from "@tsplus/stdlib/utilities/Types" 4 | -------------------------------------------------------------------------------- /packages/stdlib/_src/utilities/Lazy.ts: -------------------------------------------------------------------------------- 1 | export function lazy(f: () => A): () => A { 2 | let tmp: A | undefined 3 | let done = false 4 | return () => { 5 | if (done) { 6 | return tmp! 7 | } 8 | tmp = f() 9 | done = true 10 | return tmp! 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/stdlib/_test/Collection.test.ts: -------------------------------------------------------------------------------- 1 | describe.concurrent("Collection", () => { 2 | it("append", () => { 3 | assert.isTrue(List(0, 1, 2) == List(0) + 1 + 2) 4 | assert.isTrue(List(0, 1, 2) == List(0) < 1 < 2) 5 | }) 6 | it("prepend", () => { 7 | assert.isTrue(0 + Collection(1) == Collection(0, 1)) 8 | assert.isTrue(0 > Collection(1) == Collection(0, 1)) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_test/Covariant.test.ts: -------------------------------------------------------------------------------- 1 | describe.concurrent("Covariant", () => { 2 | it("map", () => { 3 | const result = pipe(10, Identity.Covariant.map((n) => `ok: ${n + 1}`)) 4 | assert.strictEqual(result, "ok: 11") 5 | }) 6 | }) 7 | -------------------------------------------------------------------------------- /packages/stdlib/_test/LazyValue.test.ts: -------------------------------------------------------------------------------- 1 | describe.concurrent("LazyValue", () => { 2 | it("is lazy", () => { 3 | const lazyValue = LazyValue.make(() => ({ value: "test" })) 4 | 5 | const first = lazyValue.value 6 | const second = lazyValue.value 7 | 8 | assert.strictEqual(first, second) 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /packages/stdlib/_test/global.ts: -------------------------------------------------------------------------------- 1 | import "@tsplus/stdlib/global" 2 | 3 | /** 4 | * @tsplus global 5 | */ 6 | import { assert, describe, it } from "vitest" 7 | -------------------------------------------------------------------------------- /packages/stdlib/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "build/esm", 5 | "declarationDir": "build/dts", 6 | "tsBuildInfoFile": "build/tsbuildinfo/esm.tsbuildinfo", 7 | "tsPlusConfig": "../../tsplus.config.json", 8 | "rootDir": "_src" 9 | }, 10 | "include": ["_src/**/*.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "references": [{ "path": "packages/stdlib" }, { "path": "packages/runtime" }] 4 | } 5 | -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import { defineConfig } from "vite" 3 | 4 | export default defineConfig({ 5 | test: { 6 | include: ["packages/*/build/test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"] 7 | } 8 | }) 9 | --------------------------------------------------------------------------------