Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / exotic / @examples / well-thought-out-api.js
Size: Mime:
// so I think the most important thing was getting it working
// and now that it does, I need to connect the part that would actually use these types
// so that I know how I will use them...

// - problem: want to nest some subsets of datatypes
// - issue: all data types are accessed by index
// - possible solution: get .children from types
// - possible solution2: add .parent
// - possible solution3: make a lot of classes
// - possible solution4: make a lot of classes
//
// - problem: extending classes makes it harder to instantiate and deal with prototype building
// - issue:
//  - longer uglier syntax,
//  - or slower code,
//  - or more difficult logic (such as 2 decorators currently)
//
// - problem: want to have a "best" choice...
// - solution: could use TypeInferring
//
// - problem: need tests with our real data for 2 birds 1 stone
// - solution: ez
//
// @TODO would work with bitwise checking if & ?
// but also could just have more indexes

// https://github.com/sanctuary-js/sanctuary-def
// https://github.com/sanctuary-js/sanctuary-type-classes#TypeClass
// - should add a `curry1234` and `curry.placeholderable`
// SO WHEN THESE ARE DONE
// I SHOULD WRITE A TEST FOR THE MAIN JSON DATA
// - null, undefined, array, string, number*, boolean, object
// - could create some "tree" wrapper that does not nest properties
//   but ALWAYS provides deeply nested data as "branches"
//   and individual pieces as "leaves"
//   (which is pre much a trie I guess... damnit...)
//   then we can also wrap those in sugarjs for easy ops, but only for fun in dev when devving...

// move traverse to another file
// check the output of the other stuff
// with my updated traverser, it should be easier to control what happens at each stage
// look at steps oubtlined to David
//
// maybe could group logical pieces that have the same casting together OR
// just upgrade my deps to handle any casting... sheesh...

// could have it be a fn passing in TYpes so all are builtish...
const StringType2 = () =>
  Type({
    is: is.isString,
    coercers: [
      [+StringType, identity],
      [+MapType, cast.setToString],
      [+SetType, cast.setToString],
      [+NumberType, cast.toString],
      [+SymbolType, cast.toPrimitive],
      [+ArrayType, R.toString],
      [+ObjectType, R.toString],
      [+AnyType, R.toString],
    ],

    // always immutable for strings heh
    EMPTY: (immutable = true) => EMPTY_STRING,

    subsets: {
      JSON,
    },

    // boolean to string
    supports: [
      String,
      Map,
      Set,
      Number,
      Boolean,
      Symbol,
      Object,
      Array,
      AnyType,
    ],
    // can use params for better decisions?
    coercer(type, optional, forcedFallback) {
      switch (type) {
        case +StringType:
          return identity
        case +MapType:
        case +SetType:
          return cast.collectionToArray
        case +NumberType:
          return cast.toArray
        case +SymbolType:
          return toPrimitive
        case +ObjectType:
          return R.toString
        case +AnyType:
        default:
          return this.default
      }
    },

    // operations - maybe would just be a list of other fns?
    // changes the shape which sucks...
  })

const BooleanType2 = () =>
  Type({
    species: Boolean,
    is: is.isBooleanLike,
    cast: cast.fromIshToBoolean,
  })