Coder Social home page Coder Social logo

Idea: Generic Dict Data Mapper about jc HOT 3 CLOSED

muescha avatar muescha commented on June 11, 2024
Idea: Generic Dict Data Mapper

from jc.

Comments (3)

kellyjonbrazil avatar kellyjonbrazil commented on June 11, 2024 1

#4 (bytes) I can probably remove that code and use utils.convert_size_to_int() now.

#5 (remove quotes) can probably be added to utils as a function.

#6 (normalize keys) can probably be added to utils as a function.

The dict mapper idea is not a bad one, but probably not at the top of my priority list at the moment.

from jc.

muescha avatar muescha commented on June 11, 2024

I have made some initial attempts as a personal exploration:

I currently have a draft version, but I am not entirely satisfied with it :(

You can find the code here:

The issue I am facing is that I initially examine item_mappings and then move on to key_mappings. However, the resulting changes are not as predictable for the end user.

I believe implementing changes in a pipeline would be more effective, allowing users to define the order themselves:

mapper_options = Pipeline([
	# find matches and add results to the dict
	UpdateMapper({'http-update': matcher}),

	KeyMapper({
		'version' : 'HTTP-Version',
		'status_code': 'Status-Code',
		'status_reason': 'Status-Reason'
    }),
	KeyMapper('replace_this_key', 'replaced_key'),
	KeyMapper({'.+_change$': lambda x: x.lower()}),

	ValueMapper({'*': lambda x: x.upper()})
])
  • KeyMapper = update a key key = change(key)
  • ValueMapper = update the value value = change(value)
  • UpdateMapper = add key:values to the data dict = change(key, value)
  • ItemMapper = change the value, the function signature is value = change(key,value)

from jc.

muescha avatar muescha commented on June 11, 2024

... can probably be added to utils as a function.

yes the idea was to map helper functions (maybe all placed in utils.converter) to some dict values identified by keys.

The dict mapper idea is not a bad one, but probably not at the top of my priority list at the moment.

yes - you are right - the mapper would be out of scope of jc

While I think more about it: it is better to have it KISS than a bunch of additional code to just replace one-liners

I will close this issue, maybe reopen it when I have better and leaner implementation available

from jc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.